My Account
model has the following two associations:
has_many :expenses,
:order => 'expenses.dated_on DESC',
:dependent => :destroy
has_many :recent_expenses,
:class_name => 'Expense',
:conditions => "expenses.dated_on <= '#{Date.today}'",
:order => 'dated_on DESC',
:limit => 5
In one of my views I'm rendering recent expenses like so:
<% @account.recent_expenses.each do |expense| %>
...
<% end %>
On my development machine, on the staging server (which runs in production mode) and also on the production console, @account.recent_expenses
returns the correct list. However, on our live production server, the most recent expenses are not returned.
If I replace @account.recent_expenses
with @account.expenses
in the view, the most recent expenses are displayed, so my guess is that the #{Date.today}
part of the conditions clause is somehow being cached the first time it is executed. If I restart the production Mongrel cluster, all the latest expenses are returned correctly.
Can anyone think why this would occur and how might I change the :recent_expenses
query to prevent this from happening?
I'm using Rails 2.1.0.