Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move raising rollback to top methods to avoid raising so deep

  • Loading branch information...
commit 2eda87fa7837d8b85baace4bb9248fa8504b4fe3 1 parent c973f00
@carlosantoniodasilva authored
View
6 activerecord/lib/active_record/associations/collection_association.rb
@@ -467,9 +467,11 @@ def delete_or_destroy(records, method)
def remove_records(existing_records, records, method)
records.each { |record| callback(:before_remove, record) }
- delete_records(existing_records, method) if existing_records.any?
- records.each { |record| target.delete(record) }
+ if existing_records.any?
+ delete_records(existing_records, method) or return false
+ end
+ records.each { |record| target.delete(record) }
records.each { |record| callback(:after_remove, record) }
end
View
6 activerecord/lib/active_record/associations/has_many_association.rb
@@ -25,7 +25,9 @@ def handle_dependency
load_target.each(&:mark_for_destruction)
end
- delete_all
+ deleted_records = delete_all
+ raise ActiveRecord::Rollback unless deleted_records && deleted_records.all?(&:destroyed?)
+ deleted_records
end
end
@@ -108,7 +110,7 @@ def inverse_updates_counter_cache?(reflection = reflection)
# Deletes the records according to the <tt>:dependent</tt> option.
def delete_records(records, method)
if method == :destroy
- records.each { |r| r.destroy }
+ return false unless records.all? { |r| r.destroy }
update_counter(-records.length) unless inverse_updates_counter_cache?
else
if records == :all
Please sign in to comment.
Something went wrong with that request. Please try again.