I have a strange issue with delete rules in coredata. My data model is not so complicated. I detail here only relationships between elements :
A
----------
has_many B (optional, delete rule : Cascade)
has_many C (optional, delete rule : Cascade)
B
----------
has C (optional, delete rule : Cascade)
inv_A (delete rule : Nullify)
C
----------
has B (optional, delete rule : Nullify)
inv_A (delete rule : Nullify)
When I delete B, related C is not deleted. It is like cascade delete rule does not work...
Do you have an hint on what i am doing wrong ?
Thanks for your help
It was just a refetch issue. Stupid question... Never forget to : A) Refetch data in base after having saved B) Reload table with that new fetch result (or use a NSFetechedResultController)
The delete rule always applies to the deletion of the other entity. So when you delete a C
object, the has C
relationship will make sure the B
is removed as well. The other way around, however, the has B
relationship is only set to nullify so that’s what it does.
To clarify the situation, think about it this way: if you only had one relationship, say B references C, meaning B has a field for an object of type C. The only sensible thing for a delete rule to mean is solving the question of what should be done with said field if the object it points to should be deleted.