I know a few people who have been bitten by using this code in a class
context:
{:conditions => ['companies.created_at > ?', 7.days.ago.to_s(:db)}
If you use that with a has_many, that time code gets evaluated
immediately and baked into the finder.
Unless I'm wrong, you used to be able to use single-quotes to delay
evaluation, e.g. '#{7.days.ago.to_s(:db)}'. I say used to, because
today i was trying it and it wasn't working. Even if it still worked,
really, that's just disgusting.
So I wrote a quick patch that lets you pass a lambda to :conditions
and it will be evaluated at bind time.
http://rails.lighthouseapp.com/projects/8994-ruby-...
It seemed to work in my convoluted test case. Feedback?
on 2008-06-16 12:02