aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-10 15:46:02 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-10 15:46:02 -0200
commit2574212423022a9b8d0ed70df500273b24c1f0d3 (patch)
treee7131ea1326802066c80b7f0a6f3821cb6f55f6c /activerecord/lib
parent2a843b3538bbc88286b83562fe1bb517e01576f6 (diff)
parentcc405496ce85ee0073268baefdb2be5d4b062f91 (diff)
downloadrails-2574212423022a9b8d0ed70df500273b24c1f0d3.tar.gz
rails-2574212423022a9b8d0ed70df500273b24c1f0d3.tar.bz2
rails-2574212423022a9b8d0ed70df500273b24c1f0d3.zip
Merge pull request #11694 from Empact/association-bind-values-not-updated-on-save
Fix that a collection proxy could be cached before the save of the owner, resulting in an invalid proxy lacking the owner’s id Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 4411e5ae62..93f611dd8d 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -33,7 +33,13 @@ module ActiveRecord
reload
end
- @proxy ||= CollectionProxy.create(klass, self)
+ if owner.new_record?
+ # 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)
+ else
+ @proxy ||= CollectionProxy.create(klass, self)
+ end
end
# Implements the writer method, e.g. foo.items= for Foo.has_many :items