如果关联的受管对象没有元素,请删除受管对象 [英] Delete a managed object if the associated managed object has no elements

查看:91
本文介绍了如果关联的受管对象没有元素,请删除受管对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Core Data中有两个实体:

I have 2 entities in Core Data:

- OperationCategory
- Operation

OperationCategory 操作调用操作

操作 OperationCategory 具有一对一的关系 operationCategory

The Operation has to-one relationship to OperationCategory called operationCategory

操作关系删除规则设置为拒绝 OperationCategory 操作连接到它,则不应该删除

The operations relationship delete rule is set to Deny as an OperationCategory should not be deleted if there are still Operations connected to it

code>操作项目已被删除 OperationCategory 应自动删除。有一个聪明的方式来做到这一点,或者我必须检查操作每次保存的关系,并手动删除它吗?感谢任何输入

However if all the Operation items have been deleted the OperationCategory should be deleted automatically. Is there a smart way to do this or do I have to check the operations relationship with every save and delete it manually? Thanks for any input

推荐答案

实现 - [操作prepareForDeletion],如果操作是最后一个操作,告诉OperationCategory删除自己。

Implement -[Operation prepareForDeletion] and tell the OperationCategory to delete itself if the Operation is the last one.

这篇关于如果关联的受管对象没有元素,请删除受管对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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