• 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: Fetchspec of average related field
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fetchspec of average related field


  • Subject: Re: Fetchspec of average related field
  • From: Florijan Stamenkovic <email@hidden>
  • Date: Mon, 7 May 2007 19:20:09 +0200

Hi Drew,


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.

Is there a way to do this in EOModeler?

AFAIK, the only way you could do this in EOModeler is to use raw SQL and modify your select statement to do the appropriate sorting and result number limiting. Careful though, your SQL most likely then becomes vendor specific, and your fetch specification will not update if you make changes in your entity.


If not, I can return *all* item objects, sort by email@hiddeng, and create an array with only the top ten items in it. This seems like a lot of activity compared to allowing the database to only return the top 10 items.

Maybe you could in code add a sort ordering and a result number limit to your fetch specification. That only would work assuming that the eo adapter can translate "email@hiddeng" to appropriate SQL. Something you would have to try out. Looking at EOModeler though, this is not supported. As it is not there in the fetch spec builder. Still, might be worth a try.


Or, you could use a combination of those approaches... Something like:

1. Fetch the itemID values from the RATING table with SQL, using something like:
SELECT ITEM_ID FROM RATING
GROUP BY ITEM_ID
ORDER BY AVG(RATING) DESC
RETURN RESULTS 10


Uhm, *something like* this, I am not sure this is correct. "RETURN RESULTS" is OpenBase specific I think, I don't really know the standard keyword for limiting the number of returned results.

2. Use an EOModel created fetch specification that has a qualification binding on item.itemID and bind the previously fetched IDs to it in code.

This is sweet as there is only one place where you have to worry about SQL maintenance.


Hope this helps, Flor

_______________________________________________
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


  • Follow-Ups:
    • Re: Fetchspec of average related field
      • From: Robert Walker <email@hidden>
    • Re: Fetchspec of average related field
      • From: "John Huss" <email@hidden>
References: 
 >Fetchspec of average related field (From: Drew Thoeni <email@hidden>)

  • Prev by Date: Re: Apple's Support of WebObjects
  • Next by Date: Re: Trying to create a dynamic url with the components action?
  • Previous by thread: Fetchspec of average related field
  • Next by thread: Re: Fetchspec of average related field
  • Index(es):
    • Date
    • Thread