objective-ccocoacore-dataxcode4uibuilder

CoreData create relationship when binding to NSArrayController


The setup:

CoreData Model

View Setup:

In the Cocoa documentation, it states that the Releationship Entity is not automatically create when, in this case, the product entity is allocated. I can see this behavior when I click the "+" button. The product is added to the NSTableView, but the NSTextView displays "No Context". And, if I create the product and common entities in code, I can see NSTextView display the *product_id* correctly.

I would like to be able to keep the buttons bound to the NSArrayController.

The Question:


Solution

  • In this case I don't think merely doing add: will suffice. You should link your Add button to a new action method, and in this action method you should create a Product object and a CommonData object, and then set the "common" of the former to be the latter. At least that's what I would have done.

    In any case, I think that doing some "detection" of a new CommonData object would be way of an overkill in this case.