diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-13 14:56:42 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-11-19 19:07:03 -0300 |
commit | 7df61754a5e66ed01020800bcc9903d934dbbb7b (patch) | |
tree | f49f47831fe1fc5757602e5b1d5af70a39c7fe8a /activerecord | |
parent | 09f12a12706593884961a682660f34282e937e46 (diff) | |
download | rails-7df61754a5e66ed01020800bcc9903d934dbbb7b.tar.gz rails-7df61754a5e66ed01020800bcc9903d934dbbb7b.tar.bz2 rails-7df61754a5e66ed01020800bcc9903d934dbbb7b.zip |
Remove associated records from identity map if any raised an unexpected exception.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 2b534f53ad..f417587399 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -320,22 +320,27 @@ module ActiveRecord autosave = reflection.options[:autosave] if records = associated_records_to_validate_or_save(association, @new_record_before_save, autosave) - records.each do |record| - next if record.destroyed? - - if autosave && record.marked_for_destruction? - association.destroy(record) - elsif autosave != false && (@new_record_before_save || !record.persisted?) - if autosave - saved = association.send(:insert_record, record, false, false) - else - association.send(:insert_record, record) + begin + records.each do |record| + next if record.destroyed? + + if autosave && record.marked_for_destruction? + association.destroy(record) + elsif autosave != false && (@new_record_before_save || !record.persisted?) + if autosave + saved = association.send(:insert_record, record, false, false) + else + association.send(:insert_record, record) + end + elsif autosave + saved = record.save(:validate => false) end - elsif autosave - saved = record.save(:validate => false) - end - raise ActiveRecord::Rollback if saved == false + raise ActiveRecord::Rollback if saved == false + end + rescue + records.each {|x| IdentityMap.remove(x) } if IdentityMap.enabled? + raise end end |