Florian
09/03/2021, 1:32 PMmodel A {
id String @id
// A can exist without B
mainB B? @relation(name: "AB", fields: [mainBID], references: [id])
mainBID String?
secondB B? @relation(name: "AB", fields: [secondBID], references: [id])
secondBID String?
}
enum BType {
MAIN
SECOND
}
model B {
id String @id
type BType
// B must be attached to an A to exist
a A @relation(name: "AB", fields: [aID], references: [id])
aID String
@@unique([type, aID])
}
Am I forced to do a 1-m relation (ie. replace mainB and secondB with bs B[] in model A) or is it possible to achieve something like this?
Even when I tried to add names to the relations it was still ambiguous for prisma :(
Something I didn't try but I think would look terrible, is to completely separate the 1-1 relations (i'd like to refer to A from B without needing to check type to know which key to include in the query + I need to make sure B is linked to an A), ie.
model A {
id String @id
mainB B? @relation(name: "MainAB")
secondB B? @relation(name: "SecondAB")
}
enum BType {
MAIN
SECOND
}
model B {
id String @id
type BType
mainA A? @relation(name: "MainAB", fields: [mainAID], references: [id])
mainAID String?
secondA A? @relation(name: "SecondAB", fields: [secondAID], references: [id])
secondAID String?
}
If you have any suggestion I'd be happy to hear ^^Ryan
09/03/2021, 1:42 PMB would A be related to.Ryan
09/03/2021, 1:43 PMFlorian
09/03/2021, 1:47 PMmainBID String? and secondBID String? in my first example)?Ryan
09/03/2021, 1:49 PMFlorian
09/03/2021, 1:50 PM