Module: Sequel::Plugins::SingleStatementDatasetDestroy::DatasetMethods
- Defined in:
- lib/sequel/plugins/single_statement_dataset_destroy.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy all rows in a single DELETE statement.
Instance Method Details
#destroy ⇒ Object
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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sequel/plugins/single_statement_dataset_destroy.rb', line 31 def destroy return super unless model.instance_method(:around_destroy).owner == Sequel::Model::InstanceMethods db.transaction do rows = all rows.each(&:before_destroy) expected_rows = rows.length n = delete unless n == expected_rows raise Error, "dataset changed during destroy, expected rows: #{expected_rows}, actual rows: #{n}" end rows.each(&:after_destroy) n end end |