diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-10-10 16:51:14 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-10 16:51:14 +0900 |
commit | 6c69a96048f61b280076412eab37c9134ddb7440 (patch) | |
tree | d1083c380207d34459d46171f849d12b2e13ebad /activerecord/lib/active_record/associations | |
parent | 301409a98f2bef4f431a10cae74a3430bbaca9c2 (diff) | |
parent | 961776832d13b4cea7f67aface2c2882416ac975 (diff) | |
download | rails-6c69a96048f61b280076412eab37c9134ddb7440.tar.gz rails-6c69a96048f61b280076412eab37c9134ddb7440.tar.bz2 rails-6c69a96048f61b280076412eab37c9134ddb7440.zip |
Merge pull request #34094 from christophemaximin/fix-activerecord-clearing-of-query-cache
Fix inconsistent behavior by clearing QueryCache when reloading associations
Diffstat (limited to 'activerecord/lib/active_record/associations')
3 files changed, 5 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 4686b9f517..bf4942aac8 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -40,7 +40,9 @@ module ActiveRecord end # Reloads the \target and returns +self+ on success. - def reload + # The QueryCache is cleared if +force+ is true. + def reload(force = false) + klass.connection.clear_query_cache if force && klass reset reset_scope load_target diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 9a30198b95..08b7c9274d 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -1088,7 +1088,7 @@ module ActiveRecord # person.pets.reload # fetches pets from the database # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>] def reload - proxy_association.reload + proxy_association.reload(true) reset_scope end diff --git a/activerecord/lib/active_record/associations/singular_association.rb b/activerecord/lib/active_record/associations/singular_association.rb index cfab16a745..8e50cce102 100644 --- a/activerecord/lib/active_record/associations/singular_association.rb +++ b/activerecord/lib/active_record/associations/singular_association.rb @@ -26,7 +26,7 @@ module ActiveRecord # Implements the reload reader method, e.g. foo.reload_bar for # Foo.has_one :bar def force_reload_reader - klass.uncached { reload } + reload(true) target end |