Let’s assume you are trying to find a bunch of records between a time frame.
class Call < ActiveRecord::Base
named_scope :by_month, lambda { |d| { :conditions => { :date => d.beginning_of_month..d.end_of_month } } }
end
simply specify a range
and running (the named_scope )
this_months_calls = Call.by_month Date.today
And Rails will return all the calls that were recorded during the current month. Love it.
named_scope :by_month, lambda { |d| { :conditions => ["MONTH(date) = ?", d.month ] } }
ReplyDelete(not applicable to postgresql but damn faster)
yeah well, i never really liked you :)
ReplyDeletei was never a fan of skinny Frenchmen, nor optimization :)
lol :)
ReplyDeletego, guyes go !!
DM !!
i always loves urs counterstrikes :)
@Jerome: Too bad that doesn't actually select a single month, it selects that month from all years. Fail!
ReplyDelete