如果关联的受管对象没有元素,请删除受管对象 [英] Delete a managed object if the associated managed object has no elements
问题描述
我在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 Operation
s 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屋!