Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many-to-many relationship not through linking table #24134

Open
jmwilkinson opened this issue May 8, 2024 · 0 comments
Open

Many-to-many relationship not through linking table #24134

jmwilkinson opened this issue May 8, 2024 · 0 comments
Labels
kind/feature A request for a new feature. team/client Issue for team Client. team/schema Issue for team Schema. topic: joins topic: relations

Comments

@jmwilkinson
Copy link

jmwilkinson commented May 8, 2024

Problem

Give tables a and b, where a{id, linking_id} and b{id, linking_id}, and linking_id is non-unique in both tables, it is impossible to define this relationship using prisma, and thus impossible to query it normally.

In a SQL query, this is obviously trivial:

SELECT * FROM a JOIN b ON a.linking_id = b.linking_id

Suggested solution

Allow a relationship to be defined in the schema specifying this sort of many-to-many relationships, possibly:

model a {
  id: BigInt
  linking_id: BigInt
  b b[] @relation(fields: [linking_id], references: [linking_id])
}

Additional context

Although there are workaround via raw sql, those are not composable with code that generates filtering queries and the like using prisma's standard syntax.

@Druue Druue added kind/feature A request for a new feature. topic: relations team/schema Issue for team Schema. team/client Issue for team Client. topic: joins labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for a new feature. team/client Issue for team Client. team/schema Issue for team Schema. topic: joins topic: relations
Projects
None yet
Development

No branches or pull requests

2 participants