Method: Sequel::Model::DatasetMethods#as_hash
- Defined in:
- lib/sequel/model/base.rb
#as_hash(key_column = nil, value_column = nil, opts = OPTS) ⇒ Object
This allows you to call as_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.as_hash # SELECT * FROM artists
# => {1=>#<Artist {:id=>1, ...}>,
# 2=>#<Artist {:id=>2, ...}>,
# ...}
2253 2254 2255 2256 2257 2258 2259 2260 |
# File 'lib/sequel/model/base.rb', line 2253 def as_hash(key_column=nil, value_column=nil, opts=OPTS) if key_column super else raise(Sequel::Error, "No primary key for model") unless model && (pk = model.primary_key) super(pk, value_column, opts) end end |