Spent a working day on this.
I have
class Box
has_many :users, :through => :subscriptions
end
I also have custom insert_new_users
and associate_with(new_users)
methods which use multiple INSERT to do their job quickly. Anyway, they work fine. I also have this line at the end of "associate_with" method:
def associate_with
# mysql INSERT here
self.users(true) # Should force reload
end
It works as expected when running in test environment (both controller and model tests) and it fails as expected if I remove the true
argument, which forces the reload. It also works from script/console
in development if I update_attributes
the model. But fails in development or production when I'm trying to update_attributes
from controller. It simply does not reload associations and I can see it in logs, where it says "CACHE (0.0ms)" for this query.
The weird thing - it worked before and I can't identify the moment it stopped working due to some reasons. I was hoping maybe someone knows how is this possible.