module Sequel::Dataset::DatasetSourceAlias
Public Instance Methods
from(*source, &block)
click to toggle source
Preprocess the list of sources and attempt to alias any datasets in the sources to the first source of the respective dataset.
Calls superclass method
# File lib/sequel/extensions/dataset_source_alias.rb, line 50 def from(*source, &block) virtual_row_columns(source, block) table_aliases = [] source = source.map do |s| case s when Dataset s = dataset_source_alias_expression(s, table_aliases) when Symbol, String, SQL::AliasedExpression, SQL::Identifier, SQL::QualifiedIdentifier table_aliases << alias_symbol(s) end s end super(*source, &nil) end
join_table(type, table, expr=nil, options=OPTS)
click to toggle source
If a Dataset is given as the table argument, attempt to alias it to its source.
Calls superclass method
# File lib/sequel/extensions/dataset_source_alias.rb, line 67 def join_table(type, table, expr=nil, options=OPTS) if table.is_a?(Dataset) && !options[:table_alias] table = dataset_source_alias_expression(table) end super end
Private Instance Methods
dataset_source_alias_expression(ds, table_aliases=[])
click to toggle source
Attempt to automatically alias the given dataset to its source. If the dataset cannot be automatically aliased to its source, return it unchanged. The table_aliases argument is a list of already used alias symbols, which will not be used as the alias.
# File lib/sequel/extensions/dataset_source_alias.rb, line 80 def dataset_source_alias_expression(ds, table_aliases=[]) base = ds.first_source if ds.opts[:from] case base when Symbol, String, SQL::AliasedExpression, SQL::Identifier, SQL::QualifiedIdentifier aliaz = unused_table_alias(base, table_aliases) table_aliases << aliaz ds.as(aliaz) else ds end end