Permalink
Browse files

Move raising rollback to top methods to avoid raising so deep

  • Loading branch information...
1 parent c973f00 commit 2eda87fa7837d8b85baace4bb9248fa8504b4fe3 @carlosantoniodasilva committed Mar 6, 2012
@@ -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
@@ -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

0 comments on commit 2eda87f

Please sign in to comment.