Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10771 (new defect)

Opened 8 months ago

Last modified 4 months ago

[PATCH] ActiveRecord calculations only accept one grouping field

Reported by: bscofield Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: activerecord calcuations group
Cc:

Description

Given this table for a Sample model:

id year month value
1  2007 3     1
2  2007 3     2
3  2007 4     4
4  2007 4     10
5  2007 5     12
6  2007 5     3
7  2007 5     1
8  2008 1     3

Sample.count(:id, :group => [:year, :month]) fails, as does Sample.count(:id, :group => 'year, month').

The included patch fixes this, passes all existing tests, and adds a new test for counting with multiple group fields. I'm sure it could be improved, though, so if anyone has suggestions I welcome them.

Attachments

count_by_multiple_fields.patch (7.0 kB) - added by bscofield on 01/11/08 18:53:51.

Change History

01/11/08 18:53:51 changed by bscofield

  • attachment count_by_multiple_fields.patch added.

05/06/08 00:28:08 changed by lindvall

I have submitted an updated patch (working with the latest changes on github) to lighthouse.