V
Vogon Primo
Hi guys, I'm trying to figure out how to chain together group and
select, the new finder methods in ActiveRecord 3.x so I have this
model
class Cow < ActiveRecord::Base
set_table_name :cows
belongs_to :farmer
end
with breed:string and milk_quantity:integer columns and in client
code:
result = Cow.select("breed,sum(milk_quantity) as s").group('breed').all
that runs this query
SELECT breed,sum(milk_quantity) as s FROM "cows" GROUP BY breed
And the rdb results are right :
first breed --->100
second breed --->200
and so on..
My question is:
How can access sum(milk_quantity) result from result array of Cow?
select, the new finder methods in ActiveRecord 3.x so I have this
model
class Cow < ActiveRecord::Base
set_table_name :cows
belongs_to :farmer
end
with breed:string and milk_quantity:integer columns and in client
code:
result = Cow.select("breed,sum(milk_quantity) as s").group('breed').all
that runs this query
SELECT breed,sum(milk_quantity) as s FROM "cows" GROUP BY breed
And the rdb results are right :
first breed --->100
second breed --->200
and so on..
My question is:
How can access sum(milk_quantity) result from result array of Cow?