Re: entity referencing self in relationship
Re: entity referencing self in relationship
- Subject: Re: entity referencing self in relationship
- From: Gonzalo Castro <email@hidden>
- Date: Tue, 15 May 2007 16:09:32 -0400
Hello again,
On May 14, 2007, at 4:31 AM, mmalc crawford wrote:
On May 13, 2007, at 9:22 PM, Gonzalo Castro wrote:
I am at a loss on what to do when the user clicks OK in the buddy
chooser sheet. How do I assign the selected names in the buddy
chooser to the buddies relationship attribute?
Attributes and relationships are both types of property; there is
no such thing as a "relationship attribute".
It's difficult to follow your description since you don't use terms
consistently.
Yes, I meant "buddies" is a relationship property of the "people"
entity. Sorry for the confusion.
Get the selectedObjects from the buddy array controller and add
then to the 'buddies' value of the selection of the people array
controller (mutableSetValueForKey:@"buddies").
Like this? (In the code below "people" is an outlet to the array
controller managing all the people and "peopleChooser" is an outlet
to the array controller managing the people in the table from which
the user selects buddies.)
NSArray *selObjs = [people selectedObjects];
if ( [selObjs count] > 0 )
{
[[[selObjs objectAtIndex: 0] mutableSetValueForKey: @"buddies"]
addObjectsFromArray: [peopleChooser selectedObjects]];
}
Assuming the code above is correct, how do I bind the buddy table
column in the detail portion of the main window?
This doesn't work...
value
Bind to: PeopleList (NSArrayController)
Controller Key: selection
Model Key Path: buddies
I get this error when I try to add a person to the master table;
Buddies2[486] [<NSManagedObject 0x37e380> valueForUndefinedKey:]:
this class is not key value coding-compliant for the key buddies.
The text field which displays the name is bound like this and this
works as expected.
value
Bind to: PeopleList (NSArrayController)
Controller Key: selection
Model Key Path: name
It's not clear why the content of the buddies array controller is
dependent on the arranged objects of the people array controller.
At a guess, (as a first step at least) it would make more sense for
the buddies array controller to also automatically prepare content
but use a custom 'arrangedObjects' method to filter out the
selection in the people array controller -- presumably people
cannot be their own buddies...
You're thinking ahead here and yes, it is my intention to filter the
list of buddies to choose from so the selected person isn't among the
choices. What you mean is that I should subclass NSArrayController,
override managedObjects and use an instance of this subclass to track
the contents of the left-side master table of people, right? I just
have to be careful that anyone who requests the managedObjects from
the people array controller will always get the names minus the one
that's selected.
mmalc
Gonzalo
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden