# Bug in Model.count?

**URL:** <https://www.ruby-forum.com/t/bug-in-model-count/142631>\
**Category:** Rails\
**Created:** [July 9, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/bug-in-model-count/142631 "2008-07-09T22:46:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arvias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arvias](https://www.ruby-forum.com/u/arvias)\
**Post date:** [July 9, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/bug-in-model-count/142631/1 "2008-07-09T22:46:10Z")

</div>

Hi,

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 |  
±----------±-----------------±------------------------+

–  
M.
