Browse files

Restore rescue block for when IM is enabled

  • Loading branch information...
1 parent 7101a85 commit 8799cfa72d071fe6ce78fa7dbbf5dd3c9d763a68 @pixeltrix pixeltrix committed May 24, 2013
Showing with 22 additions and 19 deletions.
  1. +22 −19 activerecord/lib/active_record/autosave_association.rb
View
41 activerecord/lib/active_record/autosave_association.rb
@@ -331,28 +331,31 @@ def save_collection_association(reflection)
autosave = reflection.options[:autosave]
if records = associated_records_to_validate_or_save(association, @new_record_before_save, autosave)
+ begin
+ if autosave
+ records_to_destroy = records.select(&:marked_for_destruction?)
+ records_to_destroy.each { |record| association.proxy.destroy(record) }
+ records -= records_to_destroy
+ end
- if autosave
- records_to_destroy = records.select(&:marked_for_destruction?)
- records_to_destroy.each { |record| association.proxy.destroy(record) }
- records -= records_to_destroy
- end
-
- records.each do |record|
-
- saved = true
-
- if autosave != false && (@new_record_before_save || record.new_record?)
- if autosave
- saved = association.insert_record(record, false)
- else
- association.insert_record(record) unless reflection.nested?
+ records.each do |record|
+ saved = true
+
+ if autosave != false && (@new_record_before_save || record.new_record?)
+ if autosave
+ saved = association.insert_record(record, false)
+ else
+ association.insert_record(record) unless reflection.nested?
+ end
+ elsif autosave
+ saved = record.save(:validate => false)
end
- elsif autosave
- saved = record.save(:validate => false)
- end
- raise ActiveRecord::Rollback unless saved
+ raise ActiveRecord::Rollback unless saved
+ end
+ rescue
+ records.each {|x| IdentityMap.remove(x) } if IdentityMap.enabled?
+ raise
end
end

0 comments on commit 8799cfa

Please sign in to comment.