Forum: Ruby on Rails Activerecord.count calculation not reurning expected output

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
John B. (Guest)
on 2009-05-08 14:35

Im using the count calculations in activerecord, see below

self.count(:id, :include => [:operating_systems], :group =>

This only returns 2 of the fields i need the id and the count:

count_id operating_systems_name_operating_systems_id
49       1
30       2

If i run the sql this generates in the log on the database itself i get
the follwoing

SELECT count(DISTINCT "products".id) AS count_id,, AS
operating_systems_name_operating_systems_id FROM "products" LEFT OUTER
JOIN "product_operating_systems" ON ("products"."id" =
"product_operating_systems"."product_id") LEFT OUTER JOIN
"operating_systems" ON ("operating_systems"."id" =
"product_operating_systems"."operating_system_id") GROUP BY,

So the above sql run on the DB i get 3 columns with the required

count_id name operating_systems_name_operating_systems_id
49       PC   1
30       MAC  2

Is there any reason for this?  Anybody got a better solution?

This topic is locked and can not be replied to.