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: zeno <email@hidden>
- Date: Wed, 22 Feb 2006 10:19:10 +0100
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?
On 2/21/06, mmalcolm crawford <email@hidden> wrote:
>
> On Feb 21, 2006, at 1:32 AM, zeno wrote:
>
> > when quitting and relaunching the app you'll loose all the KVO you
> > setup in the add<Key>Object, thus
> > you'll probably need to create a new method (called on
> > awakeFromFetch?) who will restore that...
> >
> awakeFromFetch is the appropriate method to override (for initial set-
> up).
>
> > Yeah, it would be definetly nice to have a more detailed explanation
> > to this question of the Core Data FAQ: [...]
> >
> Please file a documentation enhancement request (<http://
> bugreport.apple.com/>) or use the feedback form at the bottom of the
> documentation page.
>
> 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