On Aug 29, 2006, at 2:20 PM, John Larson wrote:

Hello,


I think the api implies they all work and will have differing outcomes depending on what you would like to 'sum' or 'count' etc. e.g., Consider the keypath: 'company.people.accounts.totalLiability'.

If I want to know how much is owed in total:
Number total = ( Number )company.valueForKeyPath ( "@sum.people.accounts.totalLiability" );

I am curious if you have actually used this?

Obviously not enough! Bummer...

I meant company.valueForKeyPath ( "[EMAIL PROTECTED]" ) - but that's still wrong. You can only provide toOne keyPaths after @sum it seems (i.e., "[EMAIL PROTECTED]" ) which will succeed (having now tested).


You can think of the keypath as a tokenized string that is evaluated recursively through the elements toward the end of the string and the @operators are looking for scalar values to iterate over and accumulate. So, for company.people.account.totalLiability where people is the only array, then [EMAIL PROTECTED] would produce the sum as desired. Suppose, however, that each person had multiple accounts. The following would also be valid: [EMAIL PROTECTED]@sum.totalLiability.

Now _that_ is some clever thinking!


The point of this was to not leave the thread with the idea that there can only be one @operator in a keypath.

And I will also add that it is quite easy to hook into KVC to implement your own "magic" operators. IIRC, there are some quite interesting things in Wonder as well as WOOgnl.

Chuck

--

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems. http://www.global-village.net/products/practical_webobjects





_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to