When using `relationMode="prisma"` (or MongoDB), provide an escape hatch to remove emulated checks from `onUpdate` and `onDelete`
See original GitHub issueProblem
We have a preview feature called referentialIntegrity
It allows users to set the datasource property relationMode
to "prisma"
or "foreignKeys"
When relationMode="prisma"
- Prisma Client emulates the behavior of the referential actions,
onUpdate
,onDelete
based on the behavior observed in SQL databases that use Foreign Keys. - Prisma Migrate does not create Foreign Keys,
For MongoDB provider, relationMode="prisma"
is the default and cannot be changed, it makes it easier to work with relations.
In some cases, people maybe want to have an alternative to this emulated behavior of Prisma Client
- In MongoDB world this is a new behavior
- some people might prefer handling relations on their own
- which I think make sense if the MongoDB database is accessed by another ORM/Client (which does not have the same behavior).
- some people might find it slower because of additional queries
- some people might prefer handling relations on their own
Suggested solution
Option 1 relationMode="none"
- Valid for all databases
- It would be a global setting where all referential actions would be invalid and show a schema validation error.
- The behavior would be that the default
onUpdate
,onDelete
does “nothing”, no checks would be performed, which means that you could break the Referential Integrity of your data. (The referenced entity might not exist)
Option 2 onUpdate="Nothing" / onDelete="Nothing"
- Valid for all databases
- Only valid if
relationMode="prisma"
- It would be a Prisma “referential action” that only exist for Prisma
- The behavior would be that
onUpdate
,onDelete
does “nothing”, no checks would be performed, which means that you could break the Referential Integrity of your data. (The referenced entity might not exist)
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top Results From Across the Web
How can i perform Cascade in mongoDb? If i delete parent the ...
// I wrote this middleware but I do not know that it is correct and how to use it in the delete topic...
Read more >Cascade style delete in Mongoose - mongodb - Stack Overflow
This is one of the primary use cases of Mongoose's 'remove' middleware. clientSchema.pre('remove', function(next) { // 'this' is the client being removed.
Read more >Good explanation of cascade (ON DELETE/UPDATE) behavior
ON DELETE NO ACTION (the default): there is no referential delete action; the referential constraint only specifies a constraint check.
Read more >Getting Started with MongoDB tutorial: Delete Data ... - YouTube
MongoDB Tutorial: Learn how to use different MongoDB delete functions, as well as MongoDB matching operators. Part of a MongoDB CRUD series.
Read more >How To Create, Retrieve, Update, and Delete Records in ...
Introduction. MongoDB is a free and open-source NoSQL document database used commonly in modern web applications. In this short tutorial, you'll ...
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 FreeTop 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
Top GitHub Comments
@janpio Yup, I just meant to reaffirm the need and agree that I see the connection to this. Sorry for the noise.
For example, I have
user
andpost
tables. A user will post many posts. But there might be some case where a post is coming to the database while its owner hasn’t been inserted into. Because the data was scrape from the internet, blockchain, random other places. I have no control or idea what data would come or lose first actually. So when inserting, updating, deleting, I need to only update the row itself, not to influence other tables. But when query, they do have relations, which needs the usage of relationMode=“prisma”.I think this scene is pretty common? Orphan entries are totally acceptable. ORM doesn’t need to assume that we must update or delete the related table’s row if one row is changed.