iPhone coredata删除通过关系连接的两个实体之间的记录
我正在我的 iPhone 应用程序中实现核心数据。它有两个实体。 实体1:最新数据 Entity2:LatestDetailedData
LastData 有 URL、发布日期、标题 LatestDetailedData 具有 URL、NewsDescription、PublishedDate、Author
两个实体都具有相同的记录 URL。 这两个实体都以逆关系连接。关系是“删除->级联”
我想要的:如果我删除LatestData中的一条记录,我希望LatestDetailedData中具有相同URL的记录也必须被删除。
如何?
I'm implementing core data in my iphone app. It has two entities.
Entity1: LatestData
Entity2: LatestDetailedData
LatestData has URL, publishedDate, heading
LatestDetailedData has URL, NewsDescription, PublishedDate, Author
Both entities have same URL for a record.
Both the entities are connected with inverse relation ship. And the relation ship is "delete->Cascaded"
What I want: If I remove a record in LatestData, I want the record with same URL in LatestDetailedData must also be deleted.
How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解正确的话,你正在使用一种关系,并且它有一个逆关系。如果是这种情况,那么当您删除一个时,Core Data 将自动删除另一个,您无需执行任何额外操作。
您看到什么表明这种情况没有发生?
更新
由于您使用多个线程,因此每个线程是否使用一个
NSManagedObjectContext
?如果是这样,您是否在保存时更新所有线程?我怀疑这两者之一没有发生,因此导致了您的问题。If I am understanding you correctly, you are using a relationship and it has an inverse. If that is the case then when you delete one then Core Data will automatically delete the other and you don't need to do anything extra.
What are you seeing that suggests that is not happening?
Update
Since you are using multiple threads, are you using one
NSManagedObjectContext
per thread? If so, are you updating all of the threads when a save occurs? I suspect one of those two is not occurring and therefore causing your issue.当您创建实体时,您也需要创建关系
如果您只是依赖 URL 字段,那么这是不好的做法。在 coredata 中设置关系,级联删除将自行处理。
when you create the entities you need to create the relationship too
if you are just relying on a URL field, then thats bad practice. Set up the relationship in coredata and the cascaded deletes will take care of themselves.