Re: valueForKey for Relationship?
Re: valueForKey for Relationship?
- Subject: Re: valueForKey for Relationship?
- From: David LeBer <email@hidden>
- Date: Thu, 2 Sep 2004 16:16:56 -0400
On 2-Sep-04, at 3:50 PM, James Cicenia wrote:
Is there a variant, I haven't found it in the api yet, that returns an
array of related objects based upon the key?
KVC gives you access to your methods. What they return is up to you.
If you have and Company object called company, and it has a
relationship defined to People called "employees" then this:
NSArray employees = (NSArray)company.valueForKey("employees");
Will return its employees.
Or if the company object is an ivar in your component then:
NSArray employees = (NSArray)this.valueForKeyPath("company.employees");
Will do the same thing within the component, and is essentially what
you are doing when you bind, say, a repetition list binding to
"company.employees" in WOBuilder.
Where it gets cool is if your People all have a firstName attribute
then:
NSArray employees =
(NSArray)this.valueForKeyPath("company.employees.firstName");
Will return an array of all of the employees firstNames, and:
this.takeValueForKeyPath("Fred", "company.employees.firstName");
Will set every employees first name to "Fred"! Well, not that you'd
really want to do that but, you get the idea...
;david
--
David LeBer
Codebase Software Systems
site: http://www.codebase.ca
blog: http://david.codebase.ca
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.