Cascade Deletes with transaction
Hi! Loving Wasp so far. Just one question at this point. How do we take advantage of prisma.$transaction() in actions.ts in order to ensure all deletes are successful? Thank you!
4 Replies
I should specify this is via the OpenSaas boilerplate.
Hey @KarateSheets , that is a great question!
Check this out: https://wasp-lang.dev/docs/data-model/entities#using-entities-directly -> you can get access to
prisma
by doing import prisma from '@wasp/dbClient'
(in docs it is named prismaClient
but it is really just prisma
.
And then you should be able to do:
Notice I used context.entities.Post
instead of prisma.post
, because I assumed you are inside of Operation (be it Action or Query) and have that available. If not, you can even go with prisma.post
, although context.entities.Post
is a bit more "by the book", in Wasp world.Entities | Wasp
Entities are the foundation of your app's data model. In short, an Entity defines a model in your database.
Thank you! This is perfect :).
Great @KarateSheets , glad to hear that :)!