Re: valueForKey for Relationship?
Re: valueForKey for Relationship?
- Subject: Re: valueForKey for Relationship?
- From: Colin Clark <email@hidden>
- Date: Thu, 2 Sep 2004 16:19:36 -0400
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.