• 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: James Cicenia <email@hidden>
  • Date: Thu, 2 Sep 2004 16:14:10 -0500

perfect! The return of Object felt singular. I am not a complete OO person yet.

By the way I just got the book!!!! Excellent.

-James


On Sep 2, 2004, at 3:19 PM, Colin Clark wrote:

Hi James,

As is, valueForKey() will return relationships. If you look at the signature for valueForKey, it returns an object of type Object, meaning that it can return anything. If you call something like valueForKey("projects") on an EO with a to-many "projects" relationship, you'll get an NSArray of EOs back.

Think about how KVC works for a moment. In essence, when you pass it a key such as "projects," it uses Java reflection to look for a method defined on your EO called getProjects(). valueForKey() will dynamically return whatever object that method is defined as returning (casted back to an Object). So, if your getProjects() method is a to-many relationship accessor and returns an NSArray, KVC will pass you back that array. This is a simplified explanation, so you'll want to look at the documentation for a better explanation of how KVC actually works.

Don't forget valueForKeyPath()--defined in NSKeyValueCodingAdditions--which allows you to specify full key paths. For example, valueForKeyPath("projects.projectManager.name") will automatically follow the relationships specified by the key path and pass you back the project manager's name. Nice.

Colin

On Thursday, September 2, 2004, at 03: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?

-James Cicenia
_______________________________________________
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.



---
Colin Clark
Dynamic Web and Database Development Lead,
Resource Centre for Academic Technology,
University of Toronto
(416) 946-7592 / email@hidden
_______________________________________________
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: 
 >Re: valueForKey for Relationship? (From: Colin Clark <email@hidden>)

  • Prev by Date: Re: OT: Java Based TEXTAREA -> HTML Library
  • Next by Date: Re: OT: Java Based TEXTAREA -> HTML Library
  • Previous by thread: Re: valueForKey for Relationship?
  • Next by thread: Re: valueForKey for Relationship?
  • Index(es):
    • Date
    • Thread