在核心数据中级联删除关系对象 [英] Deleting Relationship Objects with Cascade in Core Data

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

问题描述

我希望对Core数据执行一些简单的删除操作,但请对此提供一些建议.

I'm looking to perform some simple deletion with Core data but just need a bit of advice on this one please.

我有一个包含交易,名称,事件和日期实体的模型.交易具有指向其他每个实体的链接.

I have a model with Transaction, Name, Event and Date Entities. The Transaction has a link to each of the other Entities.

在应用程序中,当用户在文本字段中添加信息时,该信息将保存到4选项卡表视图控制器中.

In the app, when a user adds in information to text fields, that gets saved to a 4 tab table view controller.

第一个选项卡将NSFetchedResultController与交易实体上的fetchRequest一起使用.第二个选项卡使用名称实体,第三个选项卡使用事件,第四个选项卡使用日期实体.

The first tab is using NSFetchedResultController with a fetchRequest on the Transaction Entity. The second tab is using the Name Entity, the third is using the Event and the fourth is using the Date Entity.

如果我从事务"选项卡中删除一个条目,它将仅删除有意义的事务.

If I delete an entry from the Transaction tab, it deletes just that transaction which makes sense.

我想要的是能够从名称"选项卡中删除一个人,或者从事件"选项卡中删除一个事件,并通过应用程序的模型进行级联.因此,如果鲍勃有多笔交易,则删除他的交易标签会删除该笔交易.

What I want is to be able to delete a person from the Name tab, or an event from the Event tab and have that cascading through the model of the app. So if Bob has multiple transactions, deleting him the transaction tab will delete that one transaction.

如果我从名称"标签中删除BOB,则应该将其从每个日期和交易中退出的每个事件中删除.

If I delete BOB from the name tab, it should deleting him from every event that he was part off with every date and Transaction.

事件和日期也是如此.

更新为包括数据模型

注意:年份实体是实验性的,当前未使用我将如何去做这样的事情?

Note: Year Entity is experimental and currently not being used How would I go about doing something like this?

谢谢

推荐答案

如果您为 Person 的交易"关系设置了删除规则"到 Transaction 到"Cascade",然后删除一个人将自动删除所有相关交易.

If you set the "Deletion Rule" for the "transactions" relationship from Person to Transaction to "Cascade", then deleting a person will automatically delete all related transactions.

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

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