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

Delete to use the include attribute to cascade deletes #2092

Closed
kokokenada opened this issue Apr 4, 2020 · 3 comments
Closed

Delete to use the include attribute to cascade deletes #2092

kokokenada opened this issue Apr 4, 2020 · 3 comments
Labels
kind/feature A request for a new feature. team/client Issue for team Client. topic: cascade topic: referential actions
Milestone

Comments

@kokokenada
Copy link

Problem

When cleaning up data, with delete, you may get a relationship error such as:

 console.error src/services/UserService.db.spec.ts:263
    PrismaClientUnknownRequestError: 
    Invalid `prisma.user.delete()` invocation:
    
    Error occurred during query execution:
    InterpretationError("Error for binding \'4\': RelationViolation(RelationViolation { relation_name: \"CouponUseToUser\", model_a_name: \"CouponUse\", model_b_name: \"User\" })")
        at PrismaClientFetcher.request (/Users/kenono/apps/habitat/packages/back-end/node_modules/@prisma/client/runtime/index.js:1:51636)
        at processTicksAndRejections (internal/process/task_queues.js:97:5)

Solution

It would be good if the following worked (typescript likes it as is)

      await ctx.prisma.user.delete({
        where: { email_brandId: { email: uniqueEmail2, brandId: 'habitat' } },
        include: {couponUse: true}
      });

Alternatives

You can work around the problem now, by deleting the relations with a separate preceding command, but that could get dicey on a busy instance as different connections maybe used and ideally both deletes should be done in the same transaction.

Additional context

@pantharshit00 pantharshit00 added the kind/feature A request for a new feature. label Apr 8, 2020
@mrwade
Copy link

mrwade commented Jul 15, 2020

@kokokenada I was having this same issue and found this other thread that may be worth following: #2057

@matthewmueller matthewmueller added the team/client Issue for team Client. label Nov 25, 2020
@pimeys
Copy link
Contributor

pimeys commented Jun 22, 2021

Fixed in prisma/prisma-engines#1947
Proposal that's implemented is in #6996

Instructions on how to use this, and a place to give feedback: #7816

@pimeys pimeys closed this as completed Jun 22, 2021
@Jolg42 Jolg42 added this to the 2.26.0 milestone Jun 28, 2021
@janpio
Copy link
Member

janpio commented Jun 29, 2021

This has now been released as a preview feature behind a preview feature flag. You can read about it in the release notes for 2.26.0: https://github.com/prisma/prisma/releases/tag/2.26.0 If you have any feedback, please use this issue: #7816

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. topic: cascade topic: referential actions
Projects
None yet
Development

No branches or pull requests

7 participants