• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: valueForKey for Relationship?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >valueForKey for Relationship? (From: James Cicenia <email@hidden>)

  • Prev by Date: Re: valueForKey for Relationship?
  • Next by Date: Re: valueForKey for Relationship?
  • Previous by thread: Re: valueForKey for Relationship?
  • Next by thread: Re: valueForKey for Relationship?
  • Index(es):
    • Date
    • Thread