Module: Sequel::Model::DatasetMethods
- Defined in:
- lib/sequel/model/base.rb
Overview
Dataset methods are methods that the model class extends its dataset with in the call to set_dataset.
Instance Attribute Summary collapse
-
#model ⇒ Object
The model class associated with this dataset.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy each row in the dataset by instantiating it and then calling destroy on the resulting model object.
-
#to_hash(key_column = nil, value_column = nil) ⇒ Object
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.
Instance Attribute Details
#model ⇒ Object
The model class associated with this dataset
1044 1045 1046 |
# File 'lib/sequel/model/base.rb', line 1044 def model @model end |
Instance Method Details
#destroy ⇒ Object
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.
1050 1051 1052 |
# File 'lib/sequel/model/base.rb', line 1050 def destroy @db.transaction{all{|r| r.destroy}.length} end |
#to_hash(key_column = nil, value_column = nil) ⇒ Object
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.
1057 1058 1059 1060 1061 1062 1063 1064 |
# File 'lib/sequel/model/base.rb', line 1057 def to_hash(key_column=nil, value_column=nil) if key_column super else raise(Sequel::Error, "No primary key for model") unless model and pk = model.primary_key super(pk, value_column) end end |