I have a problem understanding relations and data-modeling in Prisma. I have an "easy" example about two users who can participate in a tennis game. So i have:
Model User {
id Int @id
name String
}
Model Game {
id Int @id
player1 PlayerInGame
player2 PlayerInGame
}
Model PlayerInGame {
id Int @id
player User
game Game
}
It gives me this error:
Error validating model "Game": Ambiguous relation detected. The fields `player1` and `player2` in model `Game` both refer to `PlayerInGame`. Please provide different relation names for them by adding `@relation(<name>).
How can i fix this? Thanks in advance.
I tried to at a @relation field as well, but that gave me the following error:
model Game {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
player1 PlayerInGame @relation("player1")
player2 PlayerInGame @relation("player2")
}
Error validating model "Game": Automatic related field generation would cause a naming conflict. Please add an explicit opposite relation field.