123456789_123456789_123456789_123456789_123456789_

Class: Arel::Table

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: activerecord/lib/arel/table.rb

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name: nil, as: nil, klass: nil, type_caster: klass&.type_caster) ⇒ Table

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 14

def initialize(name: nil, as: nil, klass: nil, type_caster: klass&.type_caster)
  raise ArgumentError, "A name or klass is required." unless klass || name
  name = name.name if name.is_a?(Symbol)

  @name = name
  @klass = klass
  @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

  ActiveSupport::Ractors.make_shareable(self)
end

Class Attribute Details

.engine (rw)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 9

class << self; attr_accessor :engine; end

Instance Attribute Details

#able_to_type_cast?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 117

def able_to_type_cast?
  !type_caster.nil?
end

#klass (readonly)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 12

attr_reader :table_alias, :klass

#name (rw)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 33

def name
  @name || @klass&.table_name
end

#name=(value) (rw)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 11

attr_writer :name

#table_alias (readonly)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 12

attr_reader :table_alias, :klass

#type_caster (readonly, private)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 122

attr_reader :type_caster

Instance Method Details

#==(other)

Alias for #eql?.

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 107

alias :== :eql?

#[](name, table = self)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 89

def [](name, table = self)
  name = name.name if name.is_a?(Symbol)
  name = @klass.attribute_aliases[name] || name if @klass
  Attribute.new(table, name)
end

#alias(name = "#{self.name}_2")

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 37

def alias(name = "#{self.name}_2")
  Nodes::TableAlias.new(self, name)
end

#eql?(other) ⇒ Boolean Also known as: #==

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 102

def eql?(other)
  self.class == other.class &&
    self.name == other.name &&
    self.table_alias == other.table_alias
end

#from

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 41

def from
  SelectManager.new(self)
end

#group(*columns)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 61

def group(*columns)
  from.group(*columns)
end

#hash

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 95

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)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 85

def having(expr)
  from.having expr
end

#join(relation, klass = Nodes::InnerJoin)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 45

def join(relation, klass = Nodes::InnerJoin)
  return from unless relation

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

  from.join(relation, klass)
end

#order(*expr)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 65

def order(*expr)
  from.order(*expr)
end

#outer_join(relation)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 57

def outer_join(relation)
  join(relation, Nodes::OuterJoin)
end

#project(*things)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 73

def project(*things)
  from.project(*things)
end

#skip(amount)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 81

def skip(amount)
  from.skip amount
end

#take(amount)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 77

def take(amount)
  from.take amount
end

#type_cast_for_database(attr_name, value)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 109

def type_cast_for_database(attr_name, value)
  type_caster.type_cast_for_database(attr_name, value)
end

#type_for_attribute(name)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 113

def type_for_attribute(name)
  type_caster.type_for_attribute(name)
end

#where(condition)

[ GitHub ]

  
# File 'activerecord/lib/arel/table.rb', line 69

def where(condition)
  from.where condition
end