Method: Sequel::Dataset#select_hash_groups

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

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

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

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

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

DB[:table].select_hash_groups([:first, :middle], [:last, :id])
# SELECT first, middle, last, id FROM table
# => {['a', 'b']=>[['c', 1], ['d', 2], ...], ...}

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



755
756
757
# File 'lib/sequel/dataset/actions.rb', line 755

def select_hash_groups(key_column, value_column, opts = OPTS)
  _select_hash(:to_hash_groups, key_column, value_column, opts)
end