| Module | Sequel::Model::DatasetMethods |
| In: |
lib/sequel/model/base.rb
|
Dataset methods are methods that the model class extends its dataset with in the call to set_dataset.
| model | [RW] | The model class associated with this dataset |
Destroy each row in the dataset by instantiating it and then calling destroy on the resulting model object. This isn‘t as fast as deleting the dataset, which does a single SQL call, but this runs any destroy hooks on each object in the dataset.
# File lib/sequel/model/base.rb, line 920
920: def destroy
921: @db.transaction{all{|r| r.destroy}.length}
922: end
This allows you to call to_hash without any arguments, which will result in a hash with the primary key value being the key and the model object being the value.
# File lib/sequel/model/base.rb, line 927
927: def to_hash(key_column=nil, value_column=nil)
928: if key_column
929: super
930: else
931: raise(Sequel::Error, "No primary key for model") unless model and pk = model.primary_key
932: super(pk, value_column)
933: end
934: end