aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-05-31 18:34:27 +0100
committerJon Leighton <j@jonathanleighton.com>2011-05-31 18:34:27 +0100
commit60cb96abead70eb9d510efd56013ec705baf0d63 (patch)
tree02414893308db0977346884c11166ec39a19e16f /activerecord/lib
parent0bb8429e71662aedc36ed232748d62442e74a154 (diff)
downloadrails-60cb96abead70eb9d510efd56013ec705baf0d63.tar.gz
rails-60cb96abead70eb9d510efd56013ec705baf0d63.tar.bz2
rails-60cb96abead70eb9d510efd56013ec705baf0d63.zip
Implementing @dmathieu's cleaner fix from #1425. Unfortunately he deleted the branch so I cannot just merge it.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb13
1 files changed, 5 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index c32dd77420..d0ab6b4b86 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -402,16 +402,13 @@ module ActiveRecord
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