I’ve been googling and searching the forums for some time
but can’t seem to find exactly what I’m looking for.
Suppose User HABTM Products (for example a favorites list). I would
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.