Re: Core Data: updating a key dependent on a to-many relationship?
Re: Core Data: updating a key dependent on a to-many relationship?
- Subject: Re: Core Data: updating a key dependent on a to-many relationship?
- From: Greg Herlihy <email@hidden>
- Date: Wed, 22 Feb 2006 07:45:59 -0800
- Thread-topic: Core Data: updating a key dependent on a to-many relationship?
Calling the RemoveObject routine twice would only be problematic if it were
to be called twice on the same object. It doesn't sound like we know whether
it's one or two object instances involved. So I would suggest amending the
NSLog call, perhaps with: NSLog(@"removing object for: %@", self). And then
I would compare the two entries in the log to find out whether the two are
in fact the same instance.
And they need not be the same. Although we can certainly expect one of the
objects to be yours, we cannot rule out there being one or more other
objects in existence that proxy our object. But it should be easy enough to
find out what is in fact going on.
And is there a particular reason to have the application implement these
routines (other than to count how many times they are called)? Generally, it
is just less of a nuisance to have Core Data manage an object's
relationships automatically.
Greg
On 2/22/06 1:19 AM, "zeno" <email@hidden> wrote:
> Thanks mmalc.
>
> Ok, I filed the doc enhancement request (id 4453432)...
>
> I actually found another problem, at first I thought it was my fault,
> but then I completely rebuilt a new sample app from scratch (paying
> attention to setup everything correctly) and the problem persists:
> when removing a child object (Child being the destination of the
> to-many relationship) the remove<Key>Object method is called twice.
> It's not really a problem, but I just hate when things are called
> twice without me having code it...(and also this could be a source of
> problem if I'll later have to setup/remove KVO in there)
>
> Here is how I set up things (I can share the sourcecode if you are
> interested).
> I created two Core Data entities: A and B (A being Author and B being Book).
> In A I defined a to-many relationship called "books". And then setup
> all the necessary things one is supposed to do when creating a to-many
> relationship, which are:
> - create the inverse relationship in B (called "author")
> - set the Delete Rule of the "author" relationship to Nullify
> - option-dragged both entities to IB to auto create the basic UI
> - setup the contentSet binding of the Book Array Controller to Author
> Arr. Controller -> selection.books, and checked the "Deletes Object on
> Remove"
>
> I forgot to tell the A entity's class is an NSManagedObject subclass
> called Author (I left the standard NSManagedObject for B). In the
> Author class I pasted the add<Key>Object/remove<Key>Object method that
> I got by right-clicking the "books" relationship (in the xcdatamodel
> diagram) and selecting "Copy Method Implementation To Clipboard". Then
> stuck an NSLog into removeBooksObject and noticed that whenever I
> delete a book (with either remove: or deleteObject:) the method gets
> called twice.
>
> anyone?
> mmalc?
>
_______________________________________________
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