Hi, I am trying to write a method or named_scope that will return me things based on a grouping.. AND I would like to see how many are in that group.
I've got this:
named_scope :top, :group => "view_type, view_id", :order => "count(view_id) desc", :limit => 25
Which will (correctly) return me the things with the most rows in descending order. But I would love to know how MANY rows there were in each grouping. As if I were running this sql:
SELECT *, count(view_id) FROM `trackers` GROUP BY view_type, view_id ORDER BY count(view_id) desc LIMIT 25 which will return me: 8 1 13 Genre 2008-08-12 18:54:42 2008-08-12 18:54:42 3 (<- this is the number of rows)
How can I best do this?