IssueRaiser

Support (some) weak relations with no foreign key

## Problem I need a relation in my schema so that I can query across two tables, but without the referential integrity constraints that come with a foreign key. This is related to issue #7293, but different: I am using a database that supports foreign keys (PostgreSQL) and I want them for some relations in my schema but not for others. ## Suggested solution This [this discussion](https://github.com/prisma/prisma/discussions/7274), @janpio showed me that I can do what I need if I just don't run prisma migrate after adding the relation to my schema, but I want to continue to evolve my schema and use prisma migrate in the future. So, what I really need is a way to tell Prisma that a particular relation should not have a foreign key. That could be achieved by supporting a new `weak` argument on a `@relation` attribute: ```prisma postalCode PostalCode? @relation(fields: [code], references: [code], weak: true) ``` But I would be open to any other alternative. ## Alternatives Beyond not letting prisma migrate see the relation, I don't have other ideas. ## Additional context Here are the details of my use case, which I have copied from the discussion linked above... Briefly, it's about using some relevant data, if available, to enrich another entity. The key thing is "if available". It's a weaker relationship in that you don't know if that relevant data will be there until you look, as opposed to a definite relationship between two entities that should/can be enforced.

Posted by davesteinberg on May 29, 2021, 7:18 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

support (Software)

Support (some) weak relations with no foreign key

davesteinbergMay 29, 2021, 7:18 PM

## Problem I need a relation in my schema so that I can query across two tables, but without the referential integrity constraints that come with a foreign key. This is related to issue #7293, but different: I am using a database that supports foreign keys (PostgreSQL) and I want them for some relations in my schema but not for others. ## Suggested solution This [this discussion](https://github.com/prisma/prisma/discussions/7274), @janpio showed me that I can do what I need if I just don't run prisma migrate after adding the relation to my schema, but I want to continue to evolve my schema and use prisma migrate in the future. So, what I really need is a way to tell Prisma that a particular relation should not have a foreign key. That could be achieved by supporting a new `weak` argument on a `@relation` attribute: ```prisma postalCode PostalCode? @relation(fields: [code], references: [code], weak: true) ``` But I would be open to any other alternative. ## Alternatives Beyond not letting prisma migrate see the relation, I don't have other ideas. ## Additional context Here are the details of my use case, which I have copied from the discussion linked above... Briefly, it's about using some relevant data, if available, to enrich another entity. The key thing is "if available". It's a weaker relationship in that you don't know if that relevant data will be there until you look, as opposed to a definite relationship between two entities that should/can be enforced.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue