From 7e6145b4a2108a4ad94af02c3070789c03ccbd00 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sat, 14 May 2011 19:45:26 +0100 Subject: 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) --- .../lib/active_record/associations/collection_association.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'activerecord/lib/active_record/associations/collection_association.rb') 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 -- cgit v1.2.3