Class Index [+]

Quicksearch

Sequel::Model::DatasetMethods

Dataset methods are methods that the model class extends its dataset with in the call to set_dataset.

Attributes

model[RW]

The model class associated with this dataset

  Artist.dataset.model # => Artist

Public Instance Methods

[](*args) click to toggle source

Assume if a single integer is given that it is a lookup by primary key, and call with_pk with the argument.

  Artist.dataset[1] # SELECT * FROM artists WHERE (id = 1) LIMIT 1
      # File lib/sequel/model/base.rb, line 1851
1851:       def [](*args)
1852:         if args.length == 1 && (i = args.at(0)) && i.is_a?(Integer)
1853:           with_pk(i)
1854:         else
1855:           super
1856:         end
1857:       end
destroy() click to toggle source

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)
  # ...
      # File lib/sequel/model/base.rb, line 1868
1868:       def destroy
1869:         pr = proc{all{|r| r.destroy}.length}
1870:         model.use_transactions ? @db.transaction(:server=>opts[:server], &pr) : pr.call
1871:       end
to_hash(key_column=nil, value_column=nil) click to toggle source

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, ...}>,
  #     ...}
      # File lib/sequel/model/base.rb, line 1881
1881:       def to_hash(key_column=nil, value_column=nil)
1882:         if key_column
1883:           super
1884:         else
1885:           raise(Sequel::Error, "No primary key for model") unless model and pk = model.primary_key
1886:           super(pk, value_column) 
1887:         end
1888:       end
with_pk(pk) click to toggle source

Given a primary key value, return the first record in the dataset with that primary key value.

  # Single primary key
  Artist.dataset.with_pk(1) # SELECT * FROM artists WHERE (id = 1) LIMIT 1

  # Composite primary key
  Artist.dataset.with_pk([1, 2]) # SELECT * FROM artists
                                 # WHERE ((id1 = 1) AND (id2 = 2)) LIMIT 1
      # File lib/sequel/model/base.rb, line 1899
1899:       def with_pk(pk)
1900:         first(model.qualified_primary_key_hash(pk))
1901:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.