• 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
Illegal attempt to establish a relationship 'xyz' between objects in different contexts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Illegal attempt to establish a relationship 'xyz' between objects in different contexts


  • Subject: Illegal attempt to establish a relationship 'xyz' between objects in different contexts
  • From: Alex Reynolds <email@hidden>
  • Date: Mon, 12 Oct 2009 06:27:36 -0700

I am using the CoreDataBooks sample application as a basis for pulling data into a secondary managed object context in the background, and then merging that data into the primary managed object context.

The data I am pulling in is a Book entity with a to-one relationship with an Owner entity (called "owner"). The Owner entity has a to-many relationship with the Book (called "books").

My data is an XML document of the form:

<Owner>
	<Name>alexpreynolds</Name>
	<ID>123456</ID>
</Owner>
<Books>
	<Book>Book One</Book>
	<Book>Book Two</Book>
	...
	<Book>Book N</Book>
</Books>

Book One through Book N are associated with one Owner ("alexpreynolds, 123456").

I am parsing this into an Owner instance and an NSMutableSet made up of Book instances.

When I attempt to save the first time, it saves fine and the merged data shows up in the table view.

On the second save, however, when the XML content contains a new book, it doesn't work.

Here's what happens:

I then attempt to load in an XML document that contains a new Book not already in the primary managed object context. The new Book is using the same Owner as that which is associated with the other Books.

I have routines that pick out this unique Owner managed object (which I already have in my primary managed object context) and the unique Book that is *not* found in the primary MOC.

From this, I create a new Book object in the secondary MOC, and I set its "owner" relationship to point to the unique Owner I found in the primary MOC.

When I save, I get the following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Illegal attempt to establish a relationship 'owner' between objects in different contexts (source = <Book: 0x7803590> (entity: Book; id: 0x7802ae0 <x-coredata:///Book/t527F06B2-3EB5-47CF-9A29-985B0D3758862 > ; data: {
creationDate = 2009-10-12 06:01:53 -0700;
name = nil;
nameInitial = nil;
operations = (
);
owner = nil;
type = 0;
}) , destination = <Owner: 0x78020a0> (entity: Owner; id: 0x3a56f80 <x-coredata://043AF2F0-1AD0-4078-A5E8-E9D7071D67D1/Owner/p1 > ; data: {
books = "<relationship fault: 0x7801bf0 'books'>";
displayName = alexpreynolds;
ownerID = 123456;
}))'


How do I create the new Book entity in the secondary MOC, so that I can still associate it with a pre-existing Owner in the primary MOC?

Thanks for any advice.

Regards,
Alex
_______________________________________________

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: Illegal attempt to establish a relationship 'xyz' between objects in different contexts
      • From: Alexander Spohr <email@hidden>
  • Prev by Date: Re: Appropriate dealloc and finalize actions
  • Next by Date: Re: Appropriate dealloc and finalize actions
  • Previous by thread: Re: FBOs and CAOpenGLLayers... oh my!
  • Next by thread: Re: Illegal attempt to establish a relationship 'xyz' between objects in different contexts
  • Index(es):
    • Date
    • Thread