Re: How to bind a to-many relation to a tableview?
Re: How to bind a to-many relation to a tableview?
- Subject: Re: How to bind a to-many relation to a tableview?
- From: Chris Hanson <email@hidden>
- Date: Sun, 11 Dec 2005 18:42:16 -0800
On Dec 11, 2005, at 4:27 PM, Pete Bates wrote:
OK this is probably an easy one for you pros, but I'm just going
around in circles with it.
Your question, since it involves Core Data, might be more appropriate
for Cocoa-Dev.
I have two entities: one which we'll call "clients" has a few
attributes including "clientName" and a to-many relation
("assetsOwned") to a second entity ("assets") which in turn has a
few attributes including "assetName" and a reciprocal to-one
relation to clients called "ownedBy".
Entities should generally follow class naming conventions, and be
named in the singular -- for example, Client and Asset. Also, the
convention is generally for to-many relationships to be named in the
plural -- for example, ownedAssets. This makes it easy to see at a
glance whether a relationship is to-one or to-many.
The clients array controller is bound to a popup and displays the
list of clients. When one is selected, the detail info for that
client is correctly displayed in text fields. I would like to
display a list of the client's assets in a table view, but have not
been able to discover the correct binding to do so (from IB). If I
bind the tableview's value to the clientsArrayController,
controller key: arranged objects, and model key path to
"assetsOwned.assetName I get ouput that looks like this in the table:
You need to use another array controller to represent the selected
Client's ownedAssets. You can generate one by dragging your Asset
entity into the Interface Builder document window (the window with
the instance icons in it), and when prompted tell IB to generate a
controller for many Asset objects. Then connect this Asset array
controller's "contentSet" binding to your Client array controller's
"selection" controller key and "ownedAssets" model key path. If you
want removing an Asset from this array controller to delete it from
the persistent store rather than just remove it from the
relationship, be sure to set the "Deletes Objects on Remove" option
on its "contentSet" binding too.
Set up the table view bindings for the associated Assets table as
normal, just bind them through the Asset array controller that you
just set up.
-- Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden