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.

You don't know the standard keyword because there is no "standard" keyword for limiting results. This is one of those parts of SQL that is vendor specific. You are correct that "RETURN RESULTS 10" works in OpenBase. In MySQL "LIMIT 10" would be the syntax. Other vendors may have even different syntax.

-------------------------

Now, understanding that there will be different "camps" of thinking on this, here is an alternative: Your query could get much simpler, and way more efficient, if you cache the average review value in your Item table. This would allow you to write your raw SQL against a single database table. This could drastically improve the performance of your query. The downside is that you must ensure that your model keeps this value up-to-date with any changes in your reviews. This is actually a fairly common design pattern that, slightly, breaks the Don't Repeat Yourself (DRY) principal in favor of performance. Anytime you can avoid having to join tables will make your queries much more efficient.

Just a thought, but if it were my code I'd seriously consider this alternative.

On May 7, 2007, at 1:20 PM, Florijan Stamenkovic wrote:

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 PROTECTED] 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 PROTECTED], 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 PROTECTED]" 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 protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/robertwalker1% 40mac.com

This email sent to [EMAIL PROTECTED]

--
Robert Walker
[EMAIL PROTECTED]



 _______________________________________________
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