aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2015-03-15 16:13:54 -0700
committerBen Woosley <ben.woosley@gmail.com>2015-03-15 17:29:05 -0700
commitc82cc222c793275f74fc5e8b6aa88edebe136929 (patch)
tree09c55c8d3078f9f0e8ea22cd4d65d42d40a39b70 /activerecord/lib/active_record
parenta5a4b56029f1a83cfc81852f8ca76f9161abcbaa (diff)
downloadrails-c82cc222c793275f74fc5e8b6aa88edebe136929.tar.gz
rails-c82cc222c793275f74fc5e8b6aa88edebe136929.tar.bz2
rails-c82cc222c793275f74fc5e8b6aa88edebe136929.zip
Reuse the CollectionAssociation#reader proxy cache if the foreign key is present from the start.
When a new record has the necessary information prior to save, we can avoid busting the cache. We could simply clear the @proxy on #reset or #reset_scope, but that would clear the cache more often than necessary.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 1e245926e0..88531205a1 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -33,10 +33,10 @@ module ActiveRecord
reload
end
- if owner.new_record?
+ if null_scope?
# Cache the proxy separately before the owner has an id
# or else a post-save proxy will still lack the id
- @new_record_proxy ||= CollectionProxy.create(klass, self)
+ @null_proxy ||= CollectionProxy.create(klass, self)
else
@proxy ||= CollectionProxy.create(klass, self)
end