Cascade delete #655
-
Is it possible to delete a record with all his relations (cascade delete) without using hooks to delete each related record? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 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? |
Beta Was this translation helpful? Give feedback.
-
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 :) |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
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
relationship
fields, 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?