Method: Sequel::Dataset#select_hash

Defined in:
lib/sequel/dataset/actions.rb

#select_hash(key_column, value_column, opts = OPTS) ⇒ Object

Returns a hash with key_column values as keys and value_column values as values. Similar to as_hash, but only selects the columns given. Like as_hash, it accepts an optional :hash parameter, into which entries will be merged.

DB[:table].select_hash(:id, :name)
# SELECT id, name FROM table
# => {1=>'a', 2=>'b', ...}

You can also provide an array of column names for either the key_column, the value column, or both:

DB[:table].select_hash([:id, :foo], [:name, :bar])
# SELECT id, foo, name, bar FROM table
# => {[1, 3]=>['a', 'c'], [2, 4]=>['b', 'd'], ...}

When using this method, you must be sure that each expression has an alias that Sequel can determine.



734
735
736
# File 'lib/sequel/dataset/actions.rb', line 734

def select_hash(key_column, value_column, opts = OPTS)
  _select_hash(:as_hash, key_column, value_column, opts)
end