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

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

Im using the count calculations in activerecord, see below

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

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,
operating_systems.name, operating_systems.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
operating_systems.name, operating_systems.id

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

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?

JB
This topic is locked and can not be replied to.