Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
When passing force_reload = true to an association, don't use the que…
…ry cache [#1827 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
Will authored and josh committed Dec 16, 2009
1 parent 1229ef7 commit b1bbf90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/associations.rb
Expand Up @@ -1247,7 +1247,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
Expand Down Expand Up @@ -1301,7 +1301,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
Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/associations_test.rb
Expand Up @@ -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

def test_storing_in_pstore
require "tmpdir"
Expand Down

0 comments on commit b1bbf90

Please sign in to comment.