【发布时间】:2010-11-01 05:57:49
【问题描述】:
为此花了一个工作日。
我有
class Box
has_many :users, :through => :subscriptions
end
我还有自定义的 insert_new_users 和 associate_with(new_users) 方法,它们使用多个 INSERT 快速完成工作。无论如何,他们工作得很好。我在“associate_with”方法的末尾也有这一行:
def associate_with
# mysql INSERT here
self.users(true) # Should force reload
end
它在测试环境(控制器和模型测试)中运行时按预期工作,如果我删除 true 参数,它会按预期失败,这会强制重新加载。如果我 update_attributes 模型,它也可以从 script/console 在开发中工作。但是当我尝试从控制器update_attributes 时,开发或生产失败。它根本不会重新加载关联,我可以在日志中看到它,其中显示此查询的“CACHE (0.0ms)”。
奇怪的是 - 它以前工作过,但由于某些原因,我无法确定它停止工作的那一刻。我希望也许有人知道这怎么可能。
【问题讨论】:
标签: ruby-on-rails associations reload