Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord::Calculations returns incorrect data when grouping by multiple fields

#5182

The :group option is broken for multiple fields when performing an AR calculation. See the example below:

Account.count(:all, :group => 'firm_id, credit_limit') # returns <OrderedHash {60=>1, 55=>1, 50=>1, 53=>1}>

The example above demonstrates that the returned hash incorrectly excludes data rows and columns. See below for the expected return value:

Account.count(:all, :group => 'firm_id, credit_limit') # should return <OrderedHash {[2, 60]=>1, [nil, 50]=>1, [9, 53]=>1, [6, 55]=>1, [1, 50]=>1, [6, 50]=>1}>

I have a attached a patch (test included) for supporting grouping by multiple fields. The behavior for grouping by a single field or an association is unchanged. Also, the :group option still takes in a string as always.

Reported by Alex · July 22nd, 2010 @ 11:37 PM

State: new
Milestone: none
Assigned to: nobody
Importance: Low