diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-17 00:40:26 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-28 01:19:24 +0900 |
commit | c45c9cfb011fce54c319555c8852d915ff2ef97a (patch) | |
tree | c836e64a8033845fd010dd6cfeb6e5ac7812bea0 /activerecord/lib/active_record/associations/collection_association.rb | |
parent | 9b78974bc9f0dad0242d057b69f543471af2b92d (diff) | |
download | rails-c45c9cfb011fce54c319555c8852d915ff2ef97a.tar.gz rails-c45c9cfb011fce54c319555c8852d915ff2ef97a.tar.bz2 rails-c45c9cfb011fce54c319555c8852d915ff2ef97a.zip |
Cache the association proxy object
Some third party modules expects that association returns same proxy
object each time (e.g. for stubbing collection methods:
https://github.com/rspec/rspec-rails/issues/1817).
So I decided that cache the proxy object and reset scope in the proxy
object each time.
Related context: https://github.com/rails/rails/commit/c86a32d7451c5d901620ac58630460915292f88b#commitcomment-2784312
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 62c944fce3..edc53e2517 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -30,7 +30,8 @@ module ActiveRecord reload end - CollectionProxy.create(klass, self) + @proxy ||= CollectionProxy.create(klass, self) + @proxy.reset_scope end # Implements the writer method, e.g. foo.items= for Foo.has_many :items |