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.

### Methods

destroy to_hash

### Attributes

model

[RW]

The model class associated with this dataset

      Artist.dataset.model # => Artist

### Public Instance methods

destroy()

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.

      Artist.dataset.destroy
      # DELETE FROM artists WHERE (id = 1)
      # DELETE FROM artists WHERE (id = 2)
      # ...

[Source]

          # File lib/sequel/model/base.rb, line 1424
    1424:       def destroy
    1425:         pr = proc{all{|r| r.destroy}.length}
    1426:         model.use_transactions ? @db.transaction(&pr) : pr.call
    1427:       end

to_hash(key_column=nil, value_column=nil)

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.

      Artist.dataset.to_hash # SELECT * FROM artists
      # => {1=>#<Artist {:id=>1, ...}>,
      #     2=>#<Artist {:id=>2, ...}>,
      #     ...}

[Source]

          # File lib/sequel/model/base.rb, line 1437
    1437:       def to_hash(key_column=nil, value_column=nil)
    1438:         if key_column
    1439:           super
    1440:         else
    1441:           raise(Sequel::Error, "No primary key for model") unless model and pk = model.primary_key
    1442:           super(pk, value_column)
    1443:         end
    1444:       end

[Validate]