Method: Sequel::Dataset#qualify

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

#qualify(table = (cache=true; first_source)) ⇒ Object

Qualify to the given table, or first source if no table is given.

DB[:items].where(id: 1).qualify
# SELECT items.* FROM items WHERE (items.id = 1)

DB[:items].where(id: 1).qualify(:i)
# SELECT i.* FROM items WHERE (i.id = 1)

850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
# File 'lib/sequel/dataset/query.rb', line 850

def qualify(table=(cache=true; first_source))
  o = @opts
  return self if o[:sql]

  pr = proc do
    h = {}
    (o.keys & QUALIFY_KEYS).each do |k|
      h[k] = qualified_expression(o[k], table)
    end
    h[:select] = [SQL::ColumnAll.new(table)].freeze if !o[:select] || o[:select].empty?
    clone(h)
  end

  cache ? cached_dataset(:_qualify_ds, &pr) : pr.call
end