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])
}
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?
1 Reply
EQ
EQOP2y ago
So basically what I want to achieve is something like (or even cleaner without having to use old_event)
model Event {
active_meeting Meeting? @relation(name: "active_meeting")

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

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

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

model Meeting {
event_id String? @unique
event Event? @relation(name: "active_meeting", fields: [event_id], references: [id])
old_event Event? @relation(name: "old_meetings", fields: [event_id], references: [id])
}
but this gives the following error in the image
Want results from more Discord servers?
Add your server