is it possible to delete an item in a database as ...
# orm-help
j
is it possible to delete an item in a database as soon as it is disconnected from its relation? I'm trying to avoid checking for which items need to be deleted inside my mutation and simply let prisma handle the deletion automatically.
...basically I want to use 'set' and let any items that were previously associated with connect, drop off and be deleted immediately from the database because if they're not connected to anything then I don't need them and they can be deleted.
currently what happens is it sets those fields to null, but the record itself somehow still persists in the database
p
j
@Paul Hachmang are you referring to making the changes on the database itself? I'm already using cascade deletion on the other side of the relation, and that works fine. But that doesn't solve the problem at hand.
d
I've had this exact same thought. Would love it if it were possible. Would save me a lot of complication in my resolvers
j
@Dan Hollick What I was able to do for my app was set the relation field to nullable in my data model. Now, when I disconnect a relation with
data: { set: [LIST_OF_ITEMS] }
in my resolver, that sets the the "foreign key" on the item to null and then I'm simply able to run a deleteMany mutation where that field is null. I'm not sure if that works for your app, but it was a simple workaround for me rather than trying to figure out which exact items needed to be deleted.
d
Hmmm. Interesting approach. I went the long way around and kept an array of ids
[deletedItems]
on the client and passed that along to the resolver to delete them. Adds a lot of client side complication