class Arel::Table

Attributes

engine[RW]
aliases[RW]
name[RW]
table_alias[RW]
table_name[RW]
type_caster[R]

Public Class Methods

new(name, as: nil, type_caster: nil) click to toggle source
# File lib/arel/table.rb, line 14
def initialize(name, as: nil, type_caster: nil)
  @name    = name.to_s
  @columns = nil
  @aliases = []
  @type_caster = type_caster

  # Sometime AR sends an :as parameter to table, to let the table know
  # that it is an Alias.  We may want to override new, and return a
  # TableAlias node?
  if as.to_s == @name
    as = nil
  end
  @table_alias = as
end

Public Instance Methods

==(other)
Alias for: eql?
[](name) click to toggle source
# File lib/arel/table.rb, line 83
def [] name
  ::Arel::Attribute.new self, name
end
able_to_type_cast?() click to toggle source
# File lib/arel/table.rb, line 106
def able_to_type_cast?
  !type_caster.nil?
end
alias(name = " click to toggle source
# File lib/arel/table.rb, line 29
def alias name = "#{self.name}_2"
  Nodes::TableAlias.new(self, name).tap do |node|
    @aliases << node
  end
end
eql?(other) click to toggle source
# File lib/arel/table.rb, line 94
def eql? other
  self.class == other.class &&
    self.name == other.name &&
    self.aliases == other.aliases &&
    self.table_alias == other.table_alias
end
Also aliased as: ==
from() click to toggle source
# File lib/arel/table.rb, line 35
def from
  SelectManager.new(self)
end
group(*columns) click to toggle source
# File lib/arel/table.rb, line 55
def group *columns
  from.group(*columns)
end
hash() click to toggle source
# File lib/arel/table.rb, line 87
def hash
  # Perf note: aliases and table alias is excluded from the hash
  #  aliases can have a loop back to this table breaking hashes in parent
  #  relations, for the vast majority of cases @name is unique to a query
  @name.hash
end
having(expr) click to toggle source
# File lib/arel/table.rb, line 79
def having expr
  from.having expr
end
join(relation, klass = Nodes::InnerJoin) click to toggle source
# File lib/arel/table.rb, line 39
def join relation, klass = Nodes::InnerJoin
  return from unless relation

  case relation
  when String, Nodes::SqlLiteral
    raise if relation.empty?
    klass = Nodes::StringJoin
  end

  from.join(relation, klass)
end
order(*expr) click to toggle source
# File lib/arel/table.rb, line 59
def order *expr
  from.order(*expr)
end
outer_join(relation) click to toggle source
# File lib/arel/table.rb, line 51
def outer_join relation
  join(relation, Nodes::OuterJoin)
end
project(*things) click to toggle source
# File lib/arel/table.rb, line 67
def project *things
  from.project(*things)
end
skip(amount) click to toggle source
# File lib/arel/table.rb, line 75
def skip amount
  from.skip amount
end
take(amount) click to toggle source
# File lib/arel/table.rb, line 71
def take amount
  from.take amount
end
type_cast_for_database(attribute_name, value) click to toggle source
# File lib/arel/table.rb, line 102
def type_cast_for_database(attribute_name, value)
  type_caster.type_cast_for_database(attribute_name, value)
end
where(condition) click to toggle source
# File lib/arel/table.rb, line 63
def where condition
  from.where condition
end

Private Instance Methods

attributes_for(columns) click to toggle source
# File lib/arel/table.rb, line 116
def attributes_for columns
  return nil unless columns

  columns.map do |column|
    Attributes.for(column).new self, column.name.to_sym
  end
end