aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_association.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-05-14 19:45:26 +0100
committerJon Leighton <j@jonathanleighton.com>2011-05-14 19:49:22 +0100
commit7e6145b4a2108a4ad94af02c3070789c03ccbd00 (patch)
treea37f8547283a6d111918d612d2e3ab34fc743178 /activerecord/lib/active_record/associations/collection_association.rb
parent60b23ea1da1c119eaab6d07e5a03cf3b5d5577d4 (diff)
downloadrails-7e6145b4a2108a4ad94af02c3070789c03ccbd00.tar.gz
rails-7e6145b4a2108a4ad94af02c3070789c03ccbd00.tar.bz2
rails-7e6145b4a2108a4ad94af02c3070789c03ccbd00.zip
These extra array operations appear to be unnecessary. Reasoning:
* It is not necessary to subtract 'id' from the list of copied attributes because record and mem_record are equal, so therefore their id attributes are also equal (so there is no harm in copying it, and this reduces the complexity of the code) * It is not necessary to intersect the attribute names, since record and mem_record are equal, so they have the same id and class, so they have the same columns in the database. If record has non-column attributes then it seems reasonable to also copy them onto mem_record (though I am not sure what situation this would ever happen in)
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb10
1 files changed, 2 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 50825a50f0..525ac65722 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -405,14 +405,8 @@ module ActiveRecord
mem_record = memory.delete(record)
if mem_record
- # Only try to assign attributes which exist on mem_record
- shared = mem_record.attribute_names & record.attribute_names
-
- # Don't try to assign the primary key, or attributes which have changed on mem_record
- excluded = ["id"] + mem_record.changes.keys
-
- (shared - excluded).each do |key|
- mem_record[key] = record[key]
+ (record.attribute_names - mem_record.changes.keys).each do |name|
+ mem_record[name] = record[name]
end
mem_record