Activerecord.count calculation not reurning expected output


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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs