• 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: updating a key dependent on a to-many relationship?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Nathan Tyler <email@hidden>
  • Date: Thu, 2 Feb 2006 17:37:35 -0800

Thanks for the links, that got me started.  I am writing a simple
invoice setup and need the invoice's subtotal to update when one of
the line items changes.  I have a parent object Invoice with a to-many
relationship LineItems.

I have a version of the code that works now after having some initial
issues.  I now create a new LineItem in my controller, use
addObserver:, and then use the addLineItemObject: command in Invoice.

awakeFromInsert: I know will not work because that will only be called
when it's first put into the object graph (and you can't seem to
access the inverse relationship to Invoice at that point anyway)

Is there a way to add the observer inside the LineItem object as it's
initialized (at the same time it sets the inverse relationship to
Invoice, whenever it does that)?  I'm not sure how to implement this.
Any help would be appreciated.

Thanks,

Nathan


On 1/30/06, mmalcolm crawford <email@hidden> wrote:
>
> On Jan 29, 2006, at 11:14 AM, Nathan Tyler wrote:
>
> > I am developing a Core Data application that has an entity with a
> > to-many relationship with another entity.  I need to notify the
> > parent/single object when its corresponding "many" entities are
> > edited/added/removed in order to update a total, average, etc.  In
> > this case the triggerChangeNotificationsForDependentKey will not work.
> > I have found a corresponding section in Apple's Core Data FAQ:
> > http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/
> > Articles/cdFAQ.html#//apple_ref/doc/uid/TP40001802-
> > DontLinkElementID_13
> > This seems to be the exact example of what I need.  However, as it
> > is one of my first endeavors in this area, I need some basic help on:
> > "You must add and remove the parent as an observer as child objects
> > are added to and removed from the relationship."
> > I'm not sure how to do this.
>
> See <http://developer.apple.com/documentation/Cocoa/Conceptual/
> KeyValueObserving/Concepts/KVOBasics.html#//apple_ref/doc/uid/
> 20002252> for a discussion of registering as an observer using KVO.
>
> See <http://homepage.mac.com/mmalc/CocoaExamples/controllers.html>
> [Graphics Bindings] for an example of observing an array using KVO
> and responding to changes.
 _______________________________________________
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

  • Follow-Ups:
    • Re: Core Data: updating a key dependent on a to-many relationship?
      • From: zeno <email@hidden>
  • Prev by Date: Re: Advice: Plugin preference strategy
  • Next by Date: NSDrawWindowBackground bug
  • Previous by thread: Re: Advice: Plugin preference strategy
  • Next by thread: Re: Core Data: updating a key dependent on a to-many relationship?
  • Index(es):
    • Date
    • Thread