• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data relationship question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Core Data relationship question
      • From: Felix Franz <email@hidden>
References: 
 >Core Data relationship question (From: Alex Reynolds <email@hidden>)
 >Re: Core Data relationship question (From: Felix Franz <email@hidden>)

  • Prev by Date: Re: file reading/writing over 2 gig
  • Next by Date: Re: file reading/writing over 2 gig
  • Previous by thread: Re: Core Data relationship question
  • Next by thread: Re: Core Data relationship question
  • Index(es):
    • Date
    • Thread