Max
10/19/2022, 4:39 AMnew
, packing
, shipped
. Each different state has additional fields tracking when the state was entered and other information. I'd like to create the schema so that I can query across all the different states. This is what I have so far:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
type LineItem {
productId String
name String
quantity Int
}
enum Status {
NEW
PACKING
SHIPPED
}
model NewOrder {
id String @id @default(auto()) @map("_id") @db.ObjectId
status Status @default(NEW)
lineItems LineItem[]
createdAt DateTime @default(now())
}
model PackingOrder {
id String @id @default(auto()) @map("_id") @db.ObjectId
status Status @default(PACKING)
lineItems LineItem[]
createdAt DateTime
packingStartedAt DateTime @default(now())
}
model ShippedOrder {
id String @id @default(auto()) @map("_id") @db.ObjectId
status Status @default(SHIPPED)
lineItems LineItem[]
createdAt DateTime
packingStartedAt DateTime
shippedAt DateTime @default(now())
}
Is there it possible to achieve this or am I barking up the wrong tree?
Thanks!Nurul
10/19/2022, 11:04 AMNewOrder
, PackingOrder
and ShippedOrder
models?
Basically, can a document in NewOrder have the status of Packing or Shipped?Max
10/20/2022, 11:31 AMNewOrder
would always have a status of NEW
. I added the status so that on the client I can combine results from all three models and can differentiate them by the discriminated union with status
as the discriminator.
Ideally I'd like to have all three models combined into one model for easy querying but as I understand it Prisma doesn't currently support inheritance or union types, right?Nurul
10/21/2022, 3:57 PMNurul
10/21/2022, 3:58 PMMax
10/22/2022, 4:31 AMMax
10/22/2022, 4:32 AMVladi Stevanovic