Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…eted the branch so I cannot just merge it.
  • Loading branch information...
commit 60cb96abead70eb9d510efd56013ec705baf0d63 1 parent 0bb8429
@jonleighton jonleighton authored
View
13 activerecord/lib/active_record/associations/collection_association.rb
@@ -402,16 +402,13 @@ def merge_target_lists(persisted, memory)
return memory if persisted.empty?
persisted.map! do |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)
- # To work with ruby 1.8.7
- # > 1.9 #=> mem_record = memory.delete(record)
- mem_record_index = memory.index(record)
- if mem_record_index
- mem_record = memory.at(mem_record_index)
- memory.delete_at(mem_record_index)
- end
+ 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
Please sign in to comment.
Something went wrong with that request. Please try again.