【发布时间】:2011-12-10 07:30:35
【问题描述】:
我尝试从 Core Data 中删除具有两个实体的实体 1. 根目录 2.子类
并且 RootCategory 可能有一些 ChildCategory 作为它的父级,而 ChildCategory 可能有一些 RootCategory 作为它的父级,同时尝试使用以下内容进行删除:
-(void)deleteCategory:(NSInteger)caterogyId
{
NSManagedObjectModel *dataModel = [self dataModel];
// NLog(@"%@", TO_JSON(@"results", results, nil));
RootCategory *rootCategory = (RootCategory *) [dataModel fetchOne:CD_RootCategory
predicate:@"categoryId == %d and parentChildCategory
== nil", categoryId];
if ( rootCategory.childCategorys.count != 0 ) {
// delete everything from under the leaves in this category
for ( ChildCategory *childCategory in rootCategory.childCategorys ) {
for ( RootCategory *rootCategory in childCategory.childRootCategory )
[dataModel deleteEntity:rootCategory];
}
}
}
相应的记录不会从 Core Data DB 中删除。 为什么会发生这种情况,我从两种方式调用这个 deleteEntity, 它适用于一个视图上的一组数据,并试图从另一个视图中删除另一组数据但它没有删除。
谁能解决这个问题?
【问题讨论】:
标签: iphone objective-c xcode core-data