Permalink
Browse files

Implementing @dmathieu's cleaner fix from #1425. Unfortunately he del…

…eted the branch so I cannot just merge it.
  • Loading branch information...
1 parent 1c42bd5 commit 9d179135b0b0fa334e1fd07a85e67da1dc1fc992 @jonleighton jonleighton committed May 31, 2011
Showing with 6 additions and 2 deletions.
  1. +6 −2 activerecord/lib/active_record/associations/collection_association.rb
@@ -402,9 +402,13 @@ def merge_target_lists(persisted, memory)
return memory if persisted.empty?
persisted.map! do |record|
- mem_record = memory.delete(record)
+ # Unfortunately we cannot simply do memory.delete(record) since on 1.8 this returns
+ # record rather than memory.at(memory.index(record)). The behaviour is fixed in 1.9.
+ mem_index = memory.index(record)
+
+ if mem_index
+ mem_record = memory.delete_at(mem_index)
- if mem_record
(record.attribute_names - mem_record.changes.keys).each do |name|
mem_record[name] = record[name]
end

0 comments on commit 9d17913

Please sign in to comment.