In Prisma, I'd like to model the following but I'm not really sure how.
type Event {
id: ID! @unique
players: [User]! @relation(name: "EventPlayers")
teams: [Team]! @relation(name: "EventTeams")
...
}
type User {
id: ID! @unique
eventsPlayed: [Event]! @relation(name: "EventPlayers")
...
}
type Team {
id: ID! @unique
event: Event! @relation(name: "EventTeams")
members: [User]! @relation(name: ?????)
...
}
Constraints
- Each
team member
must be in theEvent.players
- Each
Event.player
can only be assigned to one (or none) teams
Question
I have a feeling I need a many-to-many relationship here, but I'm struggling to figure this out. What do I relate Team.members
to ?????. Am I even approaching this correctly?
More info (in case it's helpful)
I intend to create a drag-n-drop interface for creating teams. Those listed in Events.players
but who have not yet been assigned as a Team.member
will be in an unassigned
bucket. Dragging them to a team, will assign them as a Team.member
. But, I will want to query all players as events { players { id }}
and events { teams { members { id }}}
Update
After giving this more thought, I'm thinking about a different way to solve this problem. Here's an updated schema I'd love your thoughts/input on.
type Event {
id: ID! @unique
users: [EventUser!]!
teams: [Team!]!
title: string
}
type EventUser {
event: Event!
user: User!
role: EventRole!
}
type User {
id: ID! @unique
events: [EventUser!]!
name: string
}
type Team {
event: Event!
members: [EventUser!]!
name: string
}
enum EventRole {
ADMIN
COORDINATOR
JUDGE
PLAYER
REVIEWER
SPONSOR
}