NSBatchDeleteRequest不删除关系 [英] NSBatchDeleteRequest does not delete relationship
问题描述
大家好,我遇到了 NSBatchDeleteRequest
问题,似乎无法删除关系引用。
Hi guys I'm having a problem with NSBatchDeleteRequest
seems that is not possible to delete relationship references.
我有两个实体:
- 新闻
- 类别
其中一个类别可以包含多个新闻。
where a category can have multiple news.
现在,当我尝试删除核心中的所有对象时使用带有以下代码的 NSBatchDeleteRequest
数据,然后查看sqlite文件似乎删除了所有类别,删除了所有新闻,但是类别和新闻之间的关系仍然存在,并且导致错误。
Now, when I try to delete all the objects in the core data using NSBatchDeleteRequest
with the following code, then looking into the sqlite file seems that all categories are deleted, all news are deleted, but the relationship between categories and news persists, and this cause faults.
此处删除功能:
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:entityName];
NSBatchDeleteRequest *delete = [[NSBatchDeleteRequest alloc] initWithFetchRequest:fetchRequest];
[delete setResultType:NSBatchDeleteResultTypeCount];
NSError *error;
NSBatchDeleteResult *results = [deleteContext executeRequest:delete error:&error];
关于如何解决此问题的任何想法?
Any idea on how to fix this?
推荐答案
您可能可以执行 [manageObjectContext reset];
这篇关于NSBatchDeleteRequest不删除关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!