Delete row and return value including data from relation

Hey everyone, I am currently rewriting a Prisma project where we are using prisma.foobar.delete({include: { RelatedData: true }}). The related data is deleted due to cascading but also returned by prisma so we can perform some finalizing based on it. Is this also possible with Drizzle (in only a single query). I found .returning() but I cannot find a way to also return data from relations any way.
2 Replies
Angelelz
Angelelz11mo ago
Prisma didn't do this in one query, it was doing running whatever necessary queries it does under the hood. I know this not because I know prisma, but because it's not possible in SQL. (for the most part) The canonical way of achieving this is deleting each record inside a transaction. You would usually have the id that you would need for both the main and the related table. This is if you don't want to rely on foreign key triggers type of deletion
Septatrix
SeptatrixOP11mo ago
I do rely on foreign key triggers for the deletion
Want results from more Discord servers?
Add your server