Re: Core Data relationship question
Re: Core Data relationship question
- Subject: Re: Core Data relationship question
- From: Alex Reynolds <email@hidden>
- Date: Mon, 13 Aug 2007 04:54:26 -0400
Many thanks!
It looks like I can also set the relationship the following way:
NSManagedObject *display = [NSEntityDescription
insertNewObjectForEntityForName: @"Display"
inManagedObjectContext:managedObjectContext];
[display setValue:targetObject forKey:@"server"];
[display didChangeValueForKey: @"server"];
(The "server" key is a relationship item.)
Compared with your approach, is my approach the wrong way to set up
the relationship?
The XML file appears to look okay, as far as the 'idrefs' attributes
in the Server and Display items, but I'm not sure.
Thanks again for your help.
-Alex
On Aug 13, 2007, at 4:39 AM, Felix Franz wrote:
Hi Alex,
you can simply use:
- (BOOL) initializeDisplayEntityForServer: (NSManagedObject *)
targetObject
{
NSManagedObject* display = [NSEntityDescription
insertNewObjectForEntityForName: @"Display" inManagedObjectContext:
managedObjectContext];
// fill out Display object ..
...
// set the relationship:
[[targetObject mutableSetValueForKey: @"displays"] addObject:
display];
return YES;
}
The objectID will be permanent after invoking save: on the
ManagedObjectContext.
(As described in <file:///Developer/ADC Reference Library/
documentation/Cocoa/Reference/CoreDataFramework/Classes/
NSManagedObject_Class/Reference/Reference.html#//apple_ref/occ/
instm/NSManagedObject/objectID>).
Cheers,
felix
----------------------------------------------------------------------
Alex Reynolds, M. Biot.
217 Leidy Building / 6013
Department of Biology
University of Pennsylvania
Philadelphia, PA 19104
V: +1 215 573.2818
F: +1 215 898.8780
E: mailto:email@hidden
W: http://www.bio.upenn.edu/computing/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden