module Sequel::Plugins::SingleStatementDatasetDestroy::DatasetMethods

  1. lib/sequel/plugins/single_statement_dataset_destroy.rb

Methods

Public Instance

  1. destroy

Public Instance methods

destroy()

Destroy all rows in a single DELETE statement. Run the before_destroy hooks for all rows before the DELETE, and all after_destroy hooks for all rows after the DELETE. If the model uses an around_destroy hook, fallback to using a separate DELETE statement per row.

[show source]
   # File lib/sequel/plugins/single_statement_dataset_destroy.rb
31 def destroy
32   return super unless model.instance_method(:around_destroy).owner == Sequel::Model::InstanceMethods
33 
34   db.transaction do
35     rows = all
36     rows.each(&:before_destroy)
37     expected_rows = rows.length
38     n = delete
39     unless n == expected_rows
40       raise Error, "dataset changed during destroy, expected rows: #{expected_rows}, actual rows: #{n}"
41     end
42     rows.each(&:after_destroy)
43     n
44   end
45 end