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:
parent
09f12a1270
commit
7df61754a5
1 changed files with 18 additions and 13 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue