aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_association.rb
diff options
context:
space:
mode:
authorErnie Miller <ernie@erniemiller.org>2012-10-05 18:36:44 -0400
committerErnie Miller <ernie@erniemiller.org>2012-10-05 18:36:44 -0400
commit9f3b8cd5a5e37583bf9356456a3fc1b3484f4294 (patch)
tree3e80041a01cc4f228127895aae007d85f8b77023 /activerecord/lib/active_record/associations/collection_association.rb
parent2b83b07307c3e5552205f33e956d3785ed3e538b (diff)
downloadrails-9f3b8cd5a5e37583bf9356456a3fc1b3484f4294.tar.gz
rails-9f3b8cd5a5e37583bf9356456a3fc1b3484f4294.tar.bz2
rails-9f3b8cd5a5e37583bf9356456a3fc1b3484f4294.zip
Fix has_many assocation w/select load after create
If you create a new record via a collection association proxy that has not loaded its target, and which selects additional attributes through the association, then when the proxy loads its target, it will inadvertently trigger an ActiveModel::MissingAttributeError during attribute writing when CollectionAssociation#merge_target_lists attempts to do its thing, since the newly loaded records will possess attributes the created record does not. This error also raises a bogus/confusing deprecation warning when accessing the association in Rails 3.2.x, so cherry-pick would be appreciated!
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 96270ec0e9..7f39d3083e 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -414,7 +414,7 @@ module ActiveRecord
persisted.map! do |record|
if mem_record = memory.delete(record)
- (record.attribute_names - mem_record.changes.keys).each do |name|
+ ((record.attribute_names & mem_record.attribute_names) - mem_record.changes.keys).each do |name|
mem_record[name] = record[name]
end