One-sided n:m relations
See original GitHub issueIn Prisma 1, it was possible to have something like
type Translation {
id: ID! @id
value: String!
language: Language!
}
type Post {
id: ID! @id @unique
title: [Translation] @relation(name: "PostTitle")
content: [Translation] @relation(name: "PostContent")
}
if I try something similar with the new prisma2 schema, I am getting
error: Error validating model “Post”: Named relations require an opposite field…
This is what I’ve tried:
model Translation {
id String @default(cuid()) @id
value String
language String
}
model Post {
id String @id @default(cuid())
title Translation[] @relation(name: "PostTitle")
content Translation[] @relation(name: "PostContent")
}
It does work when I add oppsite relationships:
model Translation {
id String @default(cuid()) @id
value String
language String
ignore1 Post[] @relation("PostTitle")
ignore2 Post[] @relation("PostContent")
}
model Post {
id String @id @default(cuid())
title Translation[] @relation(name: "PostTitle")
content Translation[] @relation(name: "PostContent")
}
But honestly, I’m not interested in those. Those will just clutter my data model and add methods I do not want to use to my client. Is there any way to avoid that? (Or will it be before prisma2 goes final?)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to Tell If You're In a One-Sided Relationship
A one-sided relationship can be defined as an imbalanced interpersonal relationship where one person invests more energy or where one person ...
Read more >Meaning of "n:m" and "1:n" in database design - Stack Overflow
m:n is used to denote a many-to-many relationship ( m objects on the other side related to n on the other) while 1:n...
Read more >Tables Relations in SQL Server: One-to-One, One-to-Many ...
In One-to-One relationship, one record of the first table will be linked to zero or one record of another table. For example, each...
Read more >Relationships - EF Core | Microsoft Learn
You can simply provide a foreign key on one side of the relationship. C# Copy. internal class ...
Read more >Many-to-many relations - Prisma
How to define and work with many-to-many relations in Prisma. ... relations refer to relations where zero or more records on one side...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m encountering this with a
createdBy
andupdatedBy
pattern and it’s leading me down a very verbose road I’m not sure I really want to follow.Consider following psuedo schema which is quite common…
I feel I should not have to be explicit about every relation to user in the user model. It should be allowed to simply be referenced in these cases.
Currently to resolve the errors we have to do something like the following
Ambiguous relation detected
and thenNamed relations require an opposite field
errors get me here.I’m facing a similar issue, where almost every table has a createdby/updatedby column. Updating the users table with alias’s is becoming a bit of a challenge. Has there been any update on this possibility ?