Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
2 replies
EQ

One to one and one to many

Hello,

I currently have
model Event {
  active_meeting_id  String?
  active_meeting     Meeting @relation(name: "active_meeting", fields: [active_meeting_id], references: [id])

  old_meetings      Meeting[]     @relation(name: "old_meetings")
}

model Meeting {
  event_id          String?
  event             Event?         @relation(name: "active_meeting")
  old_event         Event?         @relation(name: "old_meetings", fields: [event_id], references: [id])
}


But when I for example create an active meeting, the event_id stays null. Of course, I don't assign it to the active_meeting but idk how to do.

Before this, I just had an event field with Event? type and events with Event[] but a meeting can only have 1 event, not an array and both event and old_event refer to the same event.

Does someone know how to do this properly?
Was this page helpful?