Permalink
Browse files

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...
1 parent 1229ef7 commit b1bbf90dffbc412670286154d9c7749d4388806b Will committed with josh Dec 16, 2009
Showing with 12 additions and 2 deletions.
  1. +2 −2 activerecord/lib/active_record/associations.rb
  2. +10 −0 activerecord/test/cases/associations_test.rb
View
4 activerecord/lib/active_record/associations.rb
@@ -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
@@ -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
View
10 activerecord/test/cases/associations_test.rb
@@ -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"

0 comments on commit b1bbf90

Please sign in to comment.