You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The implicit syntax for m-n relations today does not support all possible cases. Certain edge cases are not yet supported, making the Query Engine crash. To support these additional edge cases we would need to do additional engineering work and add more complexity to the m-n relation syntax.
Solution
We will reduce the complexity by dropping support for the composite keys edge cases.
Referencing tables without a single unique identifier will no longer be supported in the implicit syntax. Edge cases that will no longer supported with the implicit syntax:
Given that only a subset of the cases is now supported, we can simplify the syntax, and the use of @relation to specify the foreign key field is no longer required.
model Post {
id Int @id @default(autoincrement())
- categories Category[] @relation(references: [id])+ categories Category[]
}
model Category {
id Int @id @default(autoincrement())
- posts Post[] @relation(references: [id])+ posts Post[]
}
@relation would remain as optional feature to disambiguate a relation (specs). Example:
albertoperdomo
changed the title
[Placeholder] Limit implicit relations for m-n relations to reference tables with single unique identifiers
[Placeholder] Limit implicit relations for m-n relations to work only when references are pointing to tables to single unique identifiers
Apr 21, 2020
albertoperdomo
changed the title
[Placeholder] Limit implicit relations for m-n relations to work only when references are pointing to tables to single unique identifiers
[Placeholder] Limit implicit m-n relations to models with single field id
Apr 21, 2020
albertoperdomo
changed the title
[Placeholder] Limit implicit m-n relations to models with single field id
Limit implicit m-n relations to primary keys only
Apr 30, 2020
Problem
The implicit syntax for m-n relations today does not support all possible cases. Certain edge cases are not yet supported, making the Query Engine crash. To support these additional edge cases we would need to do additional engineering work and add more complexity to the m-n relation syntax.
Solution
We will reduce the complexity by dropping support for the composite keys edge cases.
Referencing tables without a single unique identifier will no longer be supported in the implicit syntax. Edge cases that will no longer supported with the implicit syntax:
Referenced model has @unique field, but no
@id
:Referenced model has composite keys
@@id
:Referenced model has
@@unique
, but not@id
:Simplifying the Syntax
Given that only a subset of the cases is now supported, we can simplify the syntax, and the use of
@relation
to specify the foreign key field is no longer required.Old syntax using
@relation
:New syntax without
@relation
:Diff:
@relation
would remain as optional feature to disambiguate a relation (specs). Example:In the case of n-m self-relations, the use of
@relations("Name")
for disambiguation will still be required. Example:Scope
@relation
Alternatives
Additional context
Internal: https://www.notion.so/prismaio/Support-implicit-syntax-for-m-n-relations-w-composite-keys-865a5ae609d34f86a4a62e2f2410d866
The text was updated successfully, but these errors were encountered: