If you want to write a plugin that needs to read children of a record being deleted – this must be done in the Pre Validation stage.
For 1:N relations with Delete Behavior: Remove Link, the lookup to the parent being deleted is set to null somewhere between stage 10 (Pre Validation) and 20 (Pre Operation), but inside the transaction of the primary record deletion.
So if trying to retrieve the children in any stage after Pre Validation you will not get any results, as they all have a not-yet-committed update transaction where the relation is nulled.
You might agree with me that the constraints regarding cascade behavior on relationships do not quite fulfill the needs that are quite common when creating manual N:N relations.
I will publish some tricks to generically cascade delete from several parents to a manual intersect entity in an article soon to come. Stay tuned!
Unfamiliar with native / manual N:N relations? See Richard Knudson's excellent article on this topic.
Labels: Community, Plugin