核心数据打破多对多关系 [英] Core Data breaking many-to-many relationship

查看:97
本文介绍了核心数据打破多对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据模型,我想打破EntityA和EntityB之间的多对多关系。我这样做通过删除连接两者的EntityC对象。我发现EntityA仍然与EntityB有关系,虽然我保存了管理对象上下文,我可以看到EntityA记录从数据库重新获取后更改影响。
有没有什么我缺少?先感谢Sarah



解决方案

我同意Barry的说法,从你的描述听起来你正在使用多个 NSManagedObjectContext <



这是一个多线程的应用程序吗?



>



更新



其他的完整性造成这个问题。当您删除A时,从C的角度来看,与C的关系可能不会立即清除,因为Core Data会在运行循环结束时或下一次保存时执行此类清除。这意味着如果你在那些发生之前窥探值,那么关系可能就存在了。



更新



p>在你原来的问题,你说,在保存EntityA仍然与EntityB之间的关系。这是错字吗?根据你的模型EntityA和EntityB没有直接的关系。你能澄清一下吗?



或者可以显示删除EntityC的代码,以及你看到EntityA与EntityB有关系的代码。


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

解决方案

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.

这篇关于核心数据打破多对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆