Alex Rivera | Logout

rails group by multiple columns

Asked 2009-08-06T20:49:20.467
13

i have budgets table with emptype_id and calendar_id actual_head, estimated_head

when i do Budgets.sum(:actual_head ,:group=>"emptype_id,calendar_id") i do not get the result grouped by the above two columns but only by the emptype_id

however when i check the log the sql query is right

SELECT sum(`budgets`.actual_head) AS sum_actual_head, emptype_id,calendar_id AS emptype_id_calendar_id FROM `budgets` GROUP BY emptype_id,calendar_id

has 103 rows

I wanted to iterate through each emptype_id and calendar_id to get a sum of actual_head and do some calculations on it.

Edit
Report

1 Answer

3

I'm not sure of this, buy try :group => [:emptype_id, :calendar_id]

answered 2009-08-06T20:52:53.737

Your Answer