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 PROTECTED] 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 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