Created
April 7, 2009 16:05
-
-
Save tiegz/91310 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Statistic < ActiveRecord::Base | |
named_scope :by_month_and_year, :select => "DATE_FORMAT(created_at, '%b %y')", :group => "DATE_FORMAT(created_at, '%b %y')", :order => :created_at | |
end | |
>> Statistic.by_month_and_year.size | |
=> 6 # SELECT count(DATE_FORMAT(created_at, '%b %y')) AS count_date_format_created_at_b_y FROM `statistics` | |
>> Statistic.by_month_and_year.all.size | |
=> 5 # SELECT DATE_FORMAT(created_at, '%b %y') FROM `statistics` GROUP BY DATE_FORMAT(created_at, '%b %y') ORDER BY created_at |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment