This is my object model:
A Client can have many Projects (optional), but a Project must have only one Client (required). A MemoEntry can have only one Project (optional), and there can be different MemoEntry(s) with the same Project (optional).
Upon Delete:
- Client.projects has a Deny Rule
- Project.client has a Nullify Rule
- Project.memos has a Deny Rule
- MemoEntry.project has a Nullify Rule
Code that is called upon Delete of Client, Project or MemoEntry inside each of their own TableViewControllers:
// Delete the managed object.
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
[context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
NSError *error;
if (![context save:&error]) {
// Update to handle the error appropriately.
NSLog(@"MyApp - Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
Problem in bold:
If I create a Project and then delete it's parent Client, the code correctly follows into the IF
statement. If I access the "deleted" Client, it is still there and I can edit clientName
and other properties, save it and all fine. I can go to the Projects and open the Project and see the updated Client's clientName
. But when I access the Client via the Project, my app exits.
Are my delete rules not set up properly? Does calling [context save:&error]
saves the delete, even if it goes on error? Any thoughts?
*edit - Line where breakpoint error stops:
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Client" inManagedObjectContext:passedManagedObjectContext];
Error thrown:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Client''
*** Call stack at first throw:
(
0 CoreFoundation 0x30897ed3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3002f811 objc_exception_throw + 24
2 CoreData 0x3162f575 +[NSEntityDescription entityForName:inManagedObjectContext:] + 124
3 EasyMemo 0x00008ebb -[EditingViewController viewWillAppear:] + 1478
4 UIKit 0x31ec4d9b -[UINavigationController _startTransition:fromViewController:toViewController:] + 610
5 UIKit 0x31ec4ac3 -[UINavigationController _startDeferredTransitionIfNeeded] + 182
6 UIKit 0x31ebd21b -[UINavigationController pushViewController:transition:forceImmediate:] + 606
7 UIKit 0x31ebcfb3 -[UINavigationController pushViewController:animated:] + 34
8 EasyMemo 0x000058fd -[DetailProjectViewController tableView:didSelectRowAtIndexPath:] + 368
9 UIKit 0x31f7ae6f -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 662
10 UIKit 0x31f772af -[UITableView _userSelectRowAtIndexPath:] + 130
11 Foundation 0x349c7e8d __NSFireDelayedPerform + 368
12 CoreFoundation 0x3084e7fb __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
13 CoreFoundation 0x3084e2ad __CFRunLoopDoTimer + 860
14 CoreFoundation 0x3081f7a5 __CFRunLoopRun + 1088
15 CoreFoundation 0x3081f277 CFRunLoopRunSpecific + 230
16 CoreFoundation 0x3081f17f CFRunLoopRunInMode + 58
17 GraphicsServices 0x31e445f3 GSEventRunModal + 114
18 GraphicsServices 0x31e4469f GSEventRun + 62
19 UIKit 0x31e51123 -[UIApplication _run] + 402
20 UIKit 0x31e4f12f UIApplicationMain + 670
21 EasyMemo 0x0000259f main + 70
22 EasyMemo 0x00002554 start + 40
)
terminate called after throwing an instance of 'NSException'