提交 bf6af5f7 编写于 作者: W Will 提交者: Joshua Peek

When passing force_reload = true to an association, don't use the query cache...

When passing force_reload = true to an association, don't use the query cache [#1827 state:resolved]
Signed-off-by: NJoshua Peek <josh@joshpeek.com>
上级 1b27f5c4
......@@ -1325,7 +1325,7 @@ def association_accessor_methods(reflection, association_proxy_class)
if association.nil? || force_reload
association = association_proxy_class.new(self, reflection)
retval = association.reload
retval = force_reload ? reflection.klass.uncached { association.reload } : association.reload
if retval.nil? and association_proxy_class == BelongsToAssociation
association_instance_set(reflection.name, nil)
return nil
......@@ -1370,7 +1370,7 @@ def collection_reader_method(reflection, association_proxy_class)
association_instance_set(reflection.name, association)
end
association.reload if force_reload
reflection.klass.uncached { association.reload } if force_reload
association
end
......
......@@ -64,6 +64,16 @@ def test_force_reload
assert !firm.clients(true).empty?, "New firm should have reloaded client objects"
assert_equal 1, firm.clients(true).size, "New firm should have reloaded clients count"
end
def test_force_reload_is_uncached
firm = Firm.create!("name" => "A New Firm, Inc")
client = Client.create!("name" => "TheClient.com", :firm => firm)
ActiveRecord::Base.cache do
firm.clients.each {}
assert_queries(0) { assert_not_nil firm.clients.each {} }
assert_queries(1) { assert_not_nil firm.clients(true).each {} }
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册