views:

22

answers:

1

I have entities Word and Tag. Both have To-Many relationship to each other, as well as inverse. The way I need to constrain it that:

  • if I delete a Word then only the related Tags which has no Word pointing to them will be deleted
  • if I delete a Tag which has Words pointing to it then just nullify those set items.

Is it possible to model?

+1  A: 

This is something that needs to be handled in code. You need to create custom subclasses for your Word and Tag entities and implement the -prepareForDeletion method in each. Then you can check the logic and handle it appropriately. I would also set the delete rule for the relationships between the entities as deny

Marcus S. Zarra
Basically say in Word's `-prepareForDeletion` I have to check each tag and see if they are pointing to self, only then I delete the tag manually?
Michael
Other way around. When a `Word` is being deleted you need to check if the associated `Tag` relationships **ONLY** point to that Word and delete them also. Reverse that logic in the `Tag`.
Marcus S. Zarra