Here Is the related portion of my datamodel.prisma file.
type Driver {
id: ID! @unique
zones: [Zone!] @relation(name: "DriverZones")
shifts: [Shift!] @relation(name: "DriverShifts")
preferredZone: Zone
preferredShift: Shift
}
type Shift {
id: ID! @unique
drivers: [Driver! ] @relation(name: "DriverShifts")
}
type Zone {
id: ID! @unique
drivers: [Driver! ] @relation(name: "DriverZones")
}
Here I want to create the relationship for preferredZone and preferredShift to be type Zone and Shift according to the datamodel I have created. this is a one way relationship.
The relation field preferredShift
must specify a @relation
directive: @relation(name: "MyRelation")
, The relation field preferredZone
must specify a @relation
directive: @relation(name: "MyRelation")
I'm using PostgreSQL for my prisma database. How to build the relationship between preferredZone to Zone. and preferredShift to Shift.
You need to name the relations since you have two relations between same types (Driver <-> Shift and Driver <-> Zone both are connected by two relations each).
In cases like this Prisma asks you to name the relations which is what the error message you posted is about. I think this data model should work:
type Driver {
id: ID! @unique
zones: [Zone!] @relation(name: "DriverZones")
shifts: [Shift!] @relation(name: "DriverShifts")
preferredZone: Zone @relation(name: "PreferredZone")
preferredShift: Shift @relation(name: "PreferredShift")
}
type Shift {
id: ID! @unique
drivers: [Driver! ] @relation(name: "DriverShifts")
}
type Zone {
id: ID! @unique
drivers: [Driver! ] @relation(name: "DriverZones")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With