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]);
}
}
}
任何想法,我究竟做錯了什麼?
有沒有機會通過其他if/else分支之一? 「客戶」與定義的「拒絕」刪除規則有任何關係嗎? (我看到你說「不管什麼刪除規則」,但你檢查了所有的關係?) –
沒有拒絕任何實體的規則.. –
你是否100%確定如果帶有'deleteObject:'方法調用的分支被執行並且沒有保存錯誤?在手動刪除對象時,刪除規則不應該在這裏扮演任何角色。 –