This project is archived and is in readonly mode.

#5182 new

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

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

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.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>