User to Team relation with Role


#1

Im trying to model a Team with players, but want to make 1 User the owner of the team

so far i have this, but dont know how to model the relation between them, so that if the owner of the team is deleted the team is deleted, but of a regular player is deleted the player is just removed from the team

   type User {
    id: ID! @id
    name: String!
    email: String! @unique
    password: String!
    updatedAt: DateTime! @updatedAt 
    createdAt: DateTime! @createdAt
    team: Team @relation(name: "TeamToUser", onDelete: SET_NULL)
}
type Team {
    id: ID! @id
    name: String!
    shortname: String!
    updatedAt: DateTime! @updatedAt 
    createdAt: DateTime! @createdAt
    players: [User !]! @relation (name: "TeamToUser", onDelete: SET_NULL)
}

#2

add an owner field to team and an ownTeam filed to user

type User {
     
      ownTeam: [Team!]!  @relation(name: "OwnTeamToUser", onDelete: CASCADE)

}

type Team {
     owner: User! @relation(name: "OwnTeamToUser", onDelete: SET_NULL)
}

#3

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.