ActiveRecord 3 group+select

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top