• 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, Bindings, and default relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data, Bindings, and default relationships


  • Subject: Re: Core Data, Bindings, and default relationships
  • From: Chris Hanson <email@hidden>
  • Date: Mon, 20 Jun 2005 23:27:07 -0700

On Jun 20, 2005, at 10:42 PM, Christopher Frederick wrote:
(1) Purchase entity, to-many relationship to Item entity named "items"
(2) Item entity, to-one relationship to Purchase entity name "purchase"
(3) NSArrayController, Entity Name Attribute: Item
(5) "Add Item to Purchase" NSButton, bound to aforementioned NSArrayController's add: action
(6) No way to set Item.purchase to currently selected Purchase!


Or is there?

There is. Use two NSArrayControllers, one for Items (ItemsController) and one for Purchases (PurchasesController). Make sure their managedObjectContext bindings are set to the same context.


Bind ItemsController's contentSet to PurchasesController's selection.items. This means that instead of handling all Items, ItemsController handles the Items in the "items" relationship of the currently-selected Purchase. So adding an Item via ItemsController will actually add it to that relationship.

Finally, make sure that the Purchase.items relationship and the Item.purchase relationship are inverses. This means that Core Data will automatically maintain both sides of the relationship whenever you modify one side of it. For example, it will automatically set Item.purchase for an Item if you add it to a Purchase's Purchase.items relationship. Even via an array controller.

Am I missing something elementary, or have I stumbled upon a deeper problem with Core Data bindings? Thanks in advance for any information.

There were two things I think you were missing: First, that you could bind the contentSet of your Items array controller to a relationship in Purchases, and second, that if you set relationships as inverses of each other that Core Data will automatically maintain either side when the other side changes.


  -- Chris

_______________________________________________
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, Bindings, and default relationships
      • From: Christopher Frederick <email@hidden>
    • Re: Core Data, Bindings, and default relationships
      • From: mmalcolm crawford <email@hidden>
References: 
 >Core Data, Bindings, and default relationships (From: Christopher Frederick <email@hidden>)

  • Prev by Date: How to hook up controllers to a hand generated OM?
  • Next by Date: Re: How to hook up controllers to a hand generated OM?
  • Previous by thread: Core Data, Bindings, and default relationships
  • Next by thread: Re: Core Data, Bindings, and default relationships
  • Index(es):
    • Date
    • Thread