Bug description
The following schema is invalid:
model User {
id Int @id
//
favoriteGame Game @relation("user_game")
}
model Game {
id Int @id
name String
//
userId Int
userName String
user User @relation("user_game", fields: [userId, userName], references: [id])
}
because:
- The
fields in the @relation of model Game has two values, so references must have two values as well
- In order for
references to have two values, the User model must have a unique contraint on two fields.
The correct schema should be:
model User {
id Int
name String
//
favoriteGame Game @relation("user_game")
@@id(fields: [id, name])
}
model Game {
id Int @id
name String
//
userId Int
userName String
user User @relation("user_game", fields: [userId, userName], references: [id, name])
}
How to reproduce
Type the above schema into a VSCode window.
Expected behavior
Red squiggly lines in the VSCode extension, and a validation error when generating Prisma Client or running Migrate commands
Prisma information
prisma: 2.0.0-alpha.1187
Environment & setup
Irrelevant
Bug description
The following schema is invalid:
because:
fieldsin the@relationof modelGamehas two values, soreferencesmust have two values as wellreferencesto have two values, theUsermodel must have a unique contraint on two fields.The correct schema should be:
How to reproduce
Type the above schema into a VSCode window.
Expected behavior
Red squiggly lines in the VSCode extension, and a validation error when generating Prisma Client or running Migrate commands
Prisma information
prisma: 2.0.0-alpha.1187
Environment & setup
Irrelevant