diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-07-19 01:18:08 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-12-25 04:55:51 +0900 |
commit | 673ed05ee96a9259ab329d909718240b9d63cc71 (patch) | |
tree | 96353723f3918fb407d03ae5cee2829b3ee745d2 | |
parent | f1217c605de2b089fd4fccb14c4d98b41a532c60 (diff) | |
download | rails-673ed05ee96a9259ab329d909718240b9d63cc71.tar.gz rails-673ed05ee96a9259ab329d909718240b9d63cc71.tar.bz2 rails-673ed05ee96a9259ab329d909718240b9d63cc71.zip |
Cache target scope for collection proxy
-rw-r--r-- | activerecord/lib/active_record/associations/association.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 84d0493a60..1cb2b2d7c6 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -83,7 +83,7 @@ module ActiveRecord end def scope - target_scope.merge(association_scope) + target_scope.merge!(association_scope) end # The scope for this association. diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 63f746688c..5b84351ef1 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -955,9 +955,8 @@ module ActiveRecord # Returns a <tt>Relation</tt> object for the records in this association def scope - @association.scope + @scope ||= @association.scope end - alias spawn scope # Equivalent to <tt>Array#==</tt>. Returns +true+ if the two arrays # contain the same number of elements and if each element is equal @@ -1089,6 +1088,7 @@ module ActiveRecord # person.pets(true) # fetches pets from the database # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>] def reload + @scope = nil proxy_association.reload self end @@ -1110,6 +1110,7 @@ module ActiveRecord # person.pets # fetches pets from the database # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>] def reset + @scope = nil proxy_association.reset proxy_association.reset_scope self |