0

我正在尝试删除一个核心数据实体,无论我使用什么删除规则,它都不起作用。它根本不做任何事情。

我正在使用 Firefox 的 Sqlite 插件来浏览核心数据数据库,并且在删除代码运行后我可以看到那里的所有行。

我的删除代码如下所示

+(void)deleteCustomerWithID:(int)customerid inManagedObjectContext:(NSManagedObjectContext  *)context
{
Customer *customer = nil;

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Customer"];
request.predicate = [NSPredicate predicateWithFormat:@"id = %d", customerid];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"organization" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];

NSError *error = nil;
NSArray *customers = [context executeFetchRequest:request error:&error];

if (!customers || ([customers count] > 1)) {
    // handle error
} else if (![customers count]) {
    // customer not found
} else {
    customer = [customers lastObject];
    [context deleteObject:customer];

    NSError *error; 
    if(![context save:&error]){
        NSLog(@"Unresolved error series %@, %@", error, [error userInfo]);
    }
}
}

任何想法我做错了什么?

4

1 回答 1

0

我不确定出了什么问题,但我最终删除了实体中的所有关系,然后重新创建它们。这似乎解决了这个问题。我现在可以成功级联删除。

于 2012-06-08T05:29:33.863 回答