This project is archived and is in readonly mode.

#588 ✓invalid
Marcelo Barbudas

Model.count not including all group fields

Reported by Marcelo Barbudas | July 10th, 2008 @ 12:44 AM | in 2.x

I am trying to get number of events of by a certain person in a time period.

My activerecord syntax is:

Event.count(:group => [ 'DATE(created_at), user_id' ])

This returns something like:

=> [["1", 3], ["3", 1], ["4", 2], ["5", 1]]

It should have an extra date field there. Running the logged query directly in mysql returns the proper result:

SELECT count(*) AS count_all, DATE(created_at), user_id AS date_created_at_user_id FROM `events` GROUP BY DATE(created_at), user_id

+-----------+------------------+-------------------------+

| count_all | DATE(created_at) | date_created_at_user_id |

+-----------+------------------+-------------------------+

| 1 | 2008-05-08 | 1 |

| 1 | 2008-06-08 | 1 |

| 1 | 2008-06-20 | 3 |

| 1 | 2008-06-24 | 1 |

| 6 | 2008-07-08 | 1 |

| 2 | 2008-07-08 | 4 |

| 1 | 2008-07-08 | 5 |

| 3 | 2008-07-09 | 1 |

| 1 | 2008-07-09 | 3 |

| 1 | 2008-07-09 | 5 |

+-----------+------------------+-------------------------+

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages