I'm trying to create a model for storing match inf...
# orm-help
j
I'm trying to create a model for storing match info for a game, but I'm getting the error
You are trying to set the relation 'BlueTeam' from 'Match' to 'Team' and are only providing a relation directive with a name on 'Match'. Please also provide the same named relation directive on the relation field on 'Team' pointing towards 'Match'.
Here's my model:
Copy code
type Match {
  id: ID! @id
  players: [Player!]! @scalarList(strategy: RELATION)
  red: Team! @relation(name: "RedTeam")
  blue: Team! @relation(name: "BlueTeam")
  winner: String!
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}

type Team {
  id: ID! @id
  top: Player! @relation(name: "Top")
  jungle: Player! @relation(name: "Jungle")
  mid: Player! @relation(name: "Mid")
  carry: Player! @relation(name: "Carry")
  support: Player! @relation(name: "Support")
  matches: [Match]! @scalarList(strategy: RELATION)
}

type Player {
  id: ID! @id
  role: String!
  matches: [Match]! @scalarList(strategy: RELATION)
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}
What is a fix for this or is there a better way to represent the teams?
h
Try this:
Copy code
type Match {
  id: ID! @id
  players: [Player!]! @scalarList(strategy: RELATION)
  red: Team! @relation(name: "RedTeam")
  blue: Team! @relation(name: "BlueTeam")
  teams: [Team!]!  @relation(name: "MatchtoUser")
  winner: String!
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}

type Team {
  id: ID! @id
  top: Player! @relation(name: "Top")
  jungle: Player! @relation(name: "Jungle")
  mid: Player! @relation(name: "Mid")
  carry: Player! @relation(name: "Carry")
  support: Player! @relation(name: "Support")
  redTeamMatches: [Match]! @relation(name: "RedTeam")
  blueTeamMatches: [Match]! @relation(name: "BlueTeam")
  matches: [Match]! @relation(name: "MatchtoUser")
}

type Player {
  id: ID! @id
  role: String!
  matches: [Match]!
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}
modify according to your needs
j
Thanks! I'll see if I can get it to do what I want.
Is this the only way to do it? I need to keep track of which team is on which side for the Match (like home or away), but for the Team it doesn't matter which side they were on in the array of matches they've participated in. Do I have to keep track of the matches in two separate arrays to make it work or is there another way?
h
If you need to keep track of something you will need to store the data for it one way or the other. You can also create a third type
MatchEvent
that can keep track of this.
j
Well that's why I had
red
and
blue
. I need to keep track of the `Team`s independently in
Match
but I don't need to keep track of the `Match`es independently in
Team
. What would
MatchEvent
look like?