Re: Fetchspec of average related field
Re: Fetchspec of average related field
- Subject: Re: Fetchspec of average related field
- From: Lachlan Deck <email@hidden>
- Date: Tue, 8 May 2007 06:48:07 +1000
On 07/05/2007, at 10:20 PM, Drew Thoeni wrote:
I have two objects: Item and a to-many child, review.
Review has an attribute called rating.
I'm trying to use a fetchspec (which appears to be an
impossibility) that returns the top 10 reviewed items. Basically,
I'd like to sort by email@hiddeng and have only 10 items
returned.
I'm not sure why you need @avg actually...
public NSArray topTenReviews() {
EOQualifier qualifier;
NSArray sortOrderings;
EOFetchSpecification fetchSpec;
qualifier = new EOKeyValueQualifier( "item",
EOQualifier.QualifierOperatorEqual, this );
sortOrderings = new NSArray( EOSortOrdering.sortOrderingWithKey
( "rating", EOSortOrdering.CompareAscending ) );
fetchSpec = new EOFetchSpecification( "Review", qualifier,
sortOrderings );
fs.setFetchLimit( 10 );
return ec.objectsWithFetchSpecification( fs );
}
This can be defined in the model as a fetchspec if you prefer.
If you do need @avg then do what John Huss suggested (and substite
"rating" above for "item.avgRating").
with regards,
--
Lachlan Deck
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden