search for: products_users

Displaying 1 result from an estimated 1 matches for "products_users".

2006 Apr 30
2
HABTM: Find sorted by number of associations
...9;'m looking for. Suppose User HABTM Products (for example a favorites list). I would like to construct a single query for finding Products ordered by the number of Users that have flagged them as favorites. Although I can construct the query using SQL a with a SELECT products.*, count(products_users.user_id) FROM products LEFT OUTER JOIN ... GROUP BY etc. - I was wondering if there''s a way to do this directly from ActiveRecord::Base.find( ...) ? I can''t seem to get the fields correct for this. Thanks, Ben