Class: Arel::Table

Inherits:
Object
  • Object
show all
Includes:
Crud, FactoryMethods
Defined in:
lib/arel/table.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FactoryMethods

#create_and, #create_false, #create_join, #create_on, #create_string_join, #create_table_alias, #create_true, #grouping, #lower

Methods included from Crud

#compile_delete, #compile_insert, #compile_update, #create_insert

Constructor Details

#initialize(name, as: nil, type_caster: nil) ⇒ Table

Returns a new instance of Table.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/arel/table.rb', line 15

def initialize(name, as: nil, type_caster: nil)
  @name    = name.to_s
  @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

Class Attribute Details

.engineObject

Returns the value of attribute engine.



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

def engine
  @engine
end

Instance Attribute Details

#nameObject Also known as: table_name

Returns the value of attribute name.



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

def name
  @name
end

#table_aliasObject

Returns the value of attribute table_alias.



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

def table_alias
  @table_alias
end

Instance Method Details

#[](name) ⇒ Object



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

def [] name
  ::Arel::Attribute.new self, name
end

#able_to_type_cast?Boolean

Returns:

  • (Boolean)


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

def able_to_type_cast?
  !type_caster.nil?
end

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



28
29
30
# File 'lib/arel/table.rb', line 28

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

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

Returns:

  • (Boolean)


91
92
93
94
95
# File 'lib/arel/table.rb', line 91

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

#fromObject



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

def from
  SelectManager.new(self)
end

#group(*columns) ⇒ Object



52
53
54
# File 'lib/arel/table.rb', line 52

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

#hashObject



84
85
86
87
88
89
# File 'lib/arel/table.rb', line 84

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) ⇒ Object



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

def having expr
  from.having expr
end

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



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/arel/table.rb', line 36

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) ⇒ Object



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

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

#outer_join(relation) ⇒ Object



48
49
50
# File 'lib/arel/table.rb', line 48

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

#project(*things) ⇒ Object



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

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

#skip(amount) ⇒ Object



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

def skip amount
  from.skip amount
end

#take(amount) ⇒ Object



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

def take amount
  from.take amount
end

#type_cast_for_database(attribute_name, value) ⇒ Object



98
99
100
# File 'lib/arel/table.rb', line 98

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

#where(condition) ⇒ Object



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

def where condition
  from.where condition
end