mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
When passing force_reload = true to an association, don't use the query cache [#1827 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
parent
1b27f5c4f7
commit
bf6af5f719
2 changed files with 12 additions and 2 deletions
|
@ -1325,7 +1325,7 @@ module ActiveRecord
|
|||
|
||||
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 @@ module ActiveRecord
|
|||
association_instance_set(reflection.name, association)
|
||||
end
|
||||
|
||||
association.reload if force_reload
|
||||
reflection.klass.uncached { association.reload } if force_reload
|
||||
|
||||
association
|
||||
end
|
||||
|
|
|
@ -65,6 +65,16 @@ class AssociationsTest < ActiveRecord::TestCase
|
|||
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
|
||||
|
||||
class AssociationProxyTest < ActiveRecord::TestCase
|
||||
|
|
Loading…
Reference in a new issue