Cascade delete #655
|
Is it possible to delete a record with all his relations (cascade delete) without using hooks to delete each related record? |
Replies: 5 comments 8 replies
|
Hey @wojciechkrol — yes, this is possible! You'll need to write some hooks to do it. You could write a hook that can be used to traverse your collection schema and find any Know what I mean? |
|
Hej @jmikrut, Thank you for your answer. I will try to make a universal hook for this and let you know if I was successful :) |
|
This would be extremely helpful to have as an option to enable on a per-collection basis where a collection would then be able check for any relationship type fields referencing itself when deleting an item. |
|
Hi, Any chance this is solved with actual cascade delete by now? |
|
Hi @jmikrut, Is there any plan to prioritise this? I'm assuming the current issue with it is that it wouldn't trigger before/after delete hooks. However this feels like pretty core functionality for relationships and would certainly be appreciated. |
Hey @wojciechkrol — yes, this is possible! You'll need to write some hooks to do it. You could write a hook that can be used to traverse your collection schema and find any
relationshipfields, and for each one, you'd read the value of the relationship field and then delete all related documents using Payload's local API.Know what I mean?