How to properly cascade delete managed objects in Core Data?

后端 未结 2 1112
耶瑟儿~
耶瑟儿~ 2021-01-01 18:47

I have a Core Data model which has three entities: A, B, and C. A has a one-to-many relationship with B, and B has a many-to-many relationship with C. The delete rule for A

相关标签:
2条回答
  • 2021-01-01 18:59

    Based on the

    Any relationships belonging to C's whose associated B's were deleted, are also removed Suggests that the B-C should also have Cascade.

    Further, if B is removed, then C's should also be deleted. Again Cascade.

    • Nullify is often used as an inverse deletion rule*

    ie. Bs relationship to A is Nullify. C relationship to B is Nulllify. Such that when C is deleted, B is NOT deleted. And when B is deleted; A is NOT deleted.

    As in this winning drawing.

    A--->>B Cascade <---- Nullify

    B--->>C Cascade <---- Nullify

    0 讨论(0)
  • 2021-01-01 19:04

    I'm certainly no Core Data expert, but reading the documentation on the various delete rule options, it seems to me that you want the B -> C relationship to be Nullify, rather than No Action. Perhaps the Bs aren't going away because the Cs are still holding references to them?

    0 讨论(0)
提交回复
热议问题