On Jul 18, 2006, at 9:41 PM, Sean McBride wrote:

>
> I have a general question about how to do something in SQLObject. I
> have two models, and Item model and a Collection model. They have a
> RelatedJoin between them because an item can be in many collections  
> and
> a collection can have many items.
>
> I want to sort the list of items by the number of collections that  
> they
> are in (i.e. those items included in the most collections first). How
> would you go about doing this with SQLObject? orderBy will only take
> strings that are column names, so I don't think that's what I want.
>

In the future, the sqlobject-discuss list is a better place to ask  
such a SQLObject specific query.

What I can tell you is you want SQL similar to:

SELECT item.*, count(collection_id) AS collection_count FROM item  
GROUP BY item_id ORDER BY collection_count desc;

Depending on what your schema looks like. You probably get the idea  
-- you need GROUP BY to create your count pseudo column which you can  
sort by.

SQLObject select supports groupBy even though I don't see it  
mentioned in the main SQLObject documentation.

--
Philip Jenvey


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss
-~----------~----~----~----~------~----~------~--~---

Reply via email to