Core Data breaking many-to-many relationship

扶醉桌前 提交于 2020-01-06 04:17:16

问题


I have the following data model and i want to break the many-to-many relationship between EntityA and EntityB. I'm doing this by removing EntityC object that connects both of them. I found that EntityA still have a relationship with EntityB although I saved the managed object context, I can see the changes take affect after EntityA records are re-fetched from database. Is there something I'm missing? Thanks in advance,Sarah


回答1:


I agree with the comment from Barry, from your description it sounds like you are using more than one NSManagedObjectContext and that will definitely cause an issue.

Is this a multi-threaded application?

Did you base this off of one of the Apple examples?

update

Referental integrity is the mostly likely cause of this issue. When you delete A, the relationship to C, from C's point of view may not be cleared immediately because Core Data does that kind of clean up either at the end of the run loop or at the next save. This means if you are peeking at the value before either of those occur, the relationship may be there. Are you look at the relationship immediately or is it hanging around a while late, i.e. after a save?

update

In your original question you stated that after the save EntityA still has a relationship to EntityB. Is this a typo? According to your model EntityA and EntityB do not have a direct relationship. Can you clarify?

or perhaps show the code where you delete EntityC and where you see EntityA having a relationship with EntityB.



来源:https://stackoverflow.com/questions/2910670/core-data-breaking-many-to-many-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!