Skip to content

Commit

Permalink
Remove associated records from identity map if any raised an unexpect…
Browse files Browse the repository at this point in the history
…ed exception.
  • Loading branch information
miloops committed Nov 19, 2010
1 parent 09f12a1 commit 7df6175
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions activerecord/lib/active_record/autosave_association.rb
Expand Up @@ -320,22 +320,27 @@ def save_collection_association(reflection)
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

Expand Down

0 comments on commit 7df6175

Please sign in to comment.