1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove associated records from identity map if any raised an unexpected exception.

This commit is contained in:
Emilio Tagua 2010-09-13 14:56:42 -03:00
parent 09f12a1270
commit 7df61754a5

View file

@ -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?
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)
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