ActiveRecord提供
reload
从数据库中重新加载模型对象属性的方法。此方法的源代码是:
# File vendor/rails/activerecord/lib/active_record/base.rb, line 2687
def reload(options = nil)
clear_aggregation_cache
clear_association_cache
@attributes.update(self.class.find(self.id, options).instance_variable_get('@attributes'))
@attributes_cache = {}
self
end
-正如你所看到的,它叫做
clear_association_cache
方法,所以肯定有关联的缓存正在进行,这可以解释你看到的行为。在保存之前,您可能应该在其中一个方法中重新加载模型。