Closed futurechimp closed 15 years ago
@futurechimp, this is a problem that many folks run into. The issue is how your named_scope is being defined. What happens is Date.today is being interpreted when the file is loaded, not when the named_scope is invoked. If you change the named_scope declaration to use a lambda as below, this will all work as expected.
named_scope :for_today, lambda {
{ :include => [:delivery => :delivery_slot],
:conditions => ['delivery_slots.date = ?', Date.today],
:order => 'delivery_slots.timeslot' }
}
This is a common mistake many people make when defining named_scopes that depend on time and is not a problem specific to Timecop.
-John
I am not totally sure whether I'm just doing something wrong or whether this is a bug, but I'm trying to find Order objects which need to be delivered on Date.today, with a named_scope like this:
and in a console session:
There are definitely no orders which have an associated Delivery which is 500 days in the future, so I'm wondering whether this is perhaps a bug with named_scope?