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

[FER] Nested / cascading deletion via DeleteArgs.select or DeleteArgs.include ? #8207

Closed
yw662 opened this issue Jul 10, 2021 · 3 comments
Closed

Comments

@yw662
Copy link

yw662 commented Jul 10, 2021

Problem

PrismaClient.<model>.delete allow passing select or include field via <Model>DeleteArgs, but it won't actually do the cascading deletion, and will raise change you are trying to make would violate the required relation if the relation is required.

Suggested solution

Since it allows the parameter, maybe it is good to make use of it.

If sth. like

prisma.user.delete({where: {id}, include: {posts}})

The suggestion is that it should delete the included posts as well, and, if the relation is required by posts, it should be allowed since it is not violating the requirement.

Alternatives

Currently it can be done by sth. like transaction([deleteMany(...), delete(...)]), or on delete cascade with an optional-but-actually-required relation.

@pantharshit00
Copy link
Contributor

Cascade deletes are now in preview and they are embedded in the schema: https://www.prisma.io/docs/concepts/components/prisma-schema/relations/referential-actions

Closing as duplicate of #4711

@yw662
Copy link
Author

yw662 commented Jul 11, 2021

@pantharshit00 It is actually more like an option for cascade deletion without on delete cascade. This will offer an option to cascade when the underlying schema is on delete set null.

@pantharshit00
Copy link
Contributor

pantharshit00 commented Jul 11, 2021

This is covered by #8197

Add your 👍 reaction there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants