views:

39

answers:

1

Let's take two Core Data entities, set up as follows:

Entity A: Car

Attributes:
    year
    model
Relationships:
    manufacturer (<<-> Manufacturer)

Entity B: Manufacturer

Attributes:
    name
    country
Relationships:
    cars (<->> Car)

Now, what I want to do is bind the display to an NSTableView where we have the model of the car in one column, followed by the manufacturer, followed by the year. Binding the model and year are no problem, but if I bind the relationship to a column in the table, I get the text of a relationship fault error in each cell in that column instead of anything I'm looking for. How can I play with the binding to allow me to display the proper manufacturer name associated with the car?

Extending the question a bit further, how could I set up another table view to display, say, other Car entries with the same manufacturer relationship?

+1  A: 

A bit more information about how you have it set up currently would be helpful. You should be able to bind to your Array Controller in exactly the same fashion as your other attributes, with the same binding and controller key. Just use the full key path manufacturer.name for the model key path.

For a to-many relationship, you use two array controllers. Set up the 'master' array controller to prepare its own content from your Core Data Manufacturer class (in Entity mode). Then, you create a secondary, 'detail' array controller. Leave the detail array controller in Class mode (with the default NSMutableDictionary class), and bind its content set to your master array controller, with the controller key set to selection and the model key path to cars.

Many many tutorials exist out there that do exactly this. I highly recommend running through one or two; I found this MacResearch.org tutorial particularly helpful. The entire series is great.

Matt B.
Ah, this is the first time I've heard of using a second array controller to assist with the task; that does make sense now that you explain it that way. I'll check out the tutorial and get back with you on it if I still have an issue with it.
Kaji