CoreData: Inverse relationships not maintained (to-one on one size, to-many on the other, with abstract classes)
CoreData: Inverse relationships not maintained (to-one on one size, to-many on the other, with abstract classes)
- Subject: CoreData: Inverse relationships not maintained (to-one on one size, to-many on the other, with abstract classes)
- From: Jim Correia <email@hidden>
- Date: Tue, 31 May 2005 15:15:51 -0400
I have a data model with abstract entities in the hierarchy. The Item
object knows about its root container (to one relationship), and the
container object knows about its items (too many relationship.)
If I manually set the value for one side of the relationship, the
other side isn't maintained automatically. I've built a fictitious
app which demonstrates the problem.
Setting either side of the relationship doesn't automatically cause
the inverse to update.
NSManagedObjectContext *context = [self managedObjectContext];
id library = [NSEntityDescription
insertNewObjectForEntityForName: @"LibraryNode"
inManagedObjectContext: context];
id libraryItem = [NSEntityDescription
insertNewObjectForEntityForName: @"MP3Item" inManagedObjectContext:
context];
id libraryItem2 = [NSEntityDescription
insertNewObjectForEntityForName: @"MP3Item" inManagedObjectContext:
context];
[libraryItem setValue: @"Fred" forKey: @"name"];
[libraryItem2 setValue: @"Bob" forKey: @"name"];
// Try setting up this side of the relationship
[libraryItem setValue: library forKey: @"root"];
NSLog(@"%@", libraryItem);
NSLog(@"%@", library);
NSLog(@"library contains item = %d", [[library valueForKey:
@"items"] containsObject: libraryItem]);
// now try setting up the other side with the second object
[[library mutableSetValueForKey: @"items"] addObject:
libraryItem2];
NSLog(@"%@", libraryItem2);
NSLog(@"%@", library);
NSLog(@"libraryItem2 root = %@", [libraryItem2 valueForKey:
@"root"]);
Full example is on my iDisk:
http://homepage.mac.com/jimcorreia/tmp/BrokenInverseRelationships.zip
What am I doing wrong?
Thanks,
Jim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden