If I delete a node that has one-to-many relations,...
# prisma-whats-new
s
If I delete a node that has one-to-many relations, are the related nodes also deleted? Or do I need to delete them manually before deleting the node that contains the relations?
d
might be faster to try that in Playground instead of waiting for answer here, don't you think ? 🙂
s
haha yes actually I just did 🙂
it seems that I need to manuallly delete them first
m
you could use the function
s
do you know if there is a way to do it in one mutation?
it's not possible apparently
@mikedklein even with a function you would have to discover relations and delete those separately ... or what solution you have in mind?
m
That is what I was suggesting I guess it wouldn’t save that much in the end but I was thinking it would be cleaner to react to the mutation with a function.
d
hm, you mean like a subscription for a delete mutation? I believe that would not work, because subscription happens after mutation is finished ... with nested relations it would not even pass through delete mutation
s
A function would have the advantage that the mutation is more transactional... If the client is responsible for first deleting the related nodes and then the "parent node", I might end up in a state where some related nodesd are deleted but the parent is not. In my case that could have quite catastrophic consequences.
d
in my opinion it's much easier to have some flag in the parent node marking it as "deleted" and update query filters accordingly ... unless you have a lot of data and you need those deleted
s
ah i like this idea. I can live with the extra data I think..
m
yeah that is a good idea plus gives you the ability to revert changes if need be 👍 @Daniel K.
s
If the data becomes a problem I could still do a cron task to delete them from time to time
thank you all, very helpful 👍