Module | Sequel::SelectRemove |
In: |
lib/sequel/extensions/select_remove.rb
|
Remove columns from the list of selected columns. If any of the currently selected columns use expressions/aliases, this will remove selected columns with the given aliases. It will also remove entries from the selection that match exactly:
# Assume columns a, b, and c in items table DB[:items] # SELECT * FROM items DB[:items].select_remove(:c) # SELECT a, b FROM items DB[:items].select(:a, Sequel[:b].as(:c), Sequel[:c].as(:b)).select_remove(:c) # SELECT a, c AS b FROM items DB[:items].select(:a, Sequel[:b][:c], Sequel[:c][:b]).select_remove(Sequel[:c][:b]) # SELECT a, b AS c FROM items
Note that there are a few cases where this method may not work correctly:
There may be other cases where this method does not work correctly, use it with caution.
# File lib/sequel/extensions/select_remove.rb, line 42 42: def select_remove(*cols) 43: if (sel = @opts[:select]) && !sel.empty? 44: select(*(columns.zip(sel).reject{|c, s| cols.include?(c)}.map{|c, s| s} - cols)) 45: else 46: select(*(columns - cols)) 47: end 48: end