Deleting won't nullify until save : is it true

2020-04-21 04:46发布

My situation : I have complex (24 entities, many relationships and many ordered to-many relationships) model in Core Data.

Now let's say, I have an entity PlayList and an entity Song, and in PlayList an ordered to-many relationship to Song. This relationship has an inverse, and both have a nullify delete-rule.

I have remarked that when I delete a Song (let's call it gangnam) that belongs to a PlayList, this song is not removed from the relationship !! I tried to fix this with the following :

  • I fixed the Apple's bug related to the to-many ordered relationships, using the excellent : KCOrderedAccessorFix. By the way, be careful if you use other solutions, because the bug is not only for the addAnObject part but also for the removeAnObject part. Result : much better but still not working : my relationship still refers to gangnam :(
  • I tried : processPendingChanges : not working.

Now,

  • If I save my context, the Song gangnam is removed.

So, my question is :

Do I have to save my context if I want to nullify the relationships ? Or am I missing something ?

I tried to reproduce the "bug" with a smaller model, but in this case, calling processPendingChanges is enough to nullify the relationship. So, if anyone has encountered the same problem/situation, I would be happy to know that I am not the only one to fight with Core Data ;)

1条回答
SAY GOODBYE
2楼-- · 2020-04-21 05:19

For a reason, the graph of the entities was not coherent (some bug of CoreData I guess, the relations and their inverse are not properly maintained). So, it refuses to delete the object. If I save, it first makes the graph coherent and then it is possible to remove the object.

查看更多
登录 后发表回答