tylim
11/30/2020, 10:53 AMmodel User {
id String @id
email String? @unique
profile Profile?
product Product[]
role ROLE @default(USER)
orders Order[]
}
model Order {
id Int @id @default(autoincrement())
buyerId String
buyer User @relation(fields: [buyerId], references: [id])
status ORDER_STATUS
seller User @relation(fields: [sellerId], references: [id])
}
User can be seller or buyer
however this is giving me errornikolasburk
model User {
id String @id
email String? @unique
ordersAsBuyer Order[] @relation("ordersAsBuyer")
ordersAsSeller Order[] @relation("ordersAsSeller")
}
model Order {
id Int @id @default(autoincrement())
buyerId String
buyer User @relation(name: "ordersAsBuyer", fields: [buyerId], references: [id])
sellerId String
seller User @relation(name: "ordersAsSeller", fields: [sellerId], references: [id])
}
Note that because you have two relations, you have to add the relations fields twice per model and provide a name
via the @relation
attribute so that the relation can be disambiguated!nikolasburk
tylim
11/30/2020, 3:10 PMnikolasburk
tylim
11/30/2020, 3:28 PM