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, options = {}) ⇒ Table

Returns a new instance of Table



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

def initialize name, options = {}
  @name    = name.to_s
  @columns = nil
  @aliases = []

  # 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?
  @table_alias = options[:as]
  if @table_alias.to_s == @name
    @table_alias = nil
  end
end

Class Attribute Details

.engineObject

Returns the value of attribute engine



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

def engine
  @engine
end

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases



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

def aliases
  @aliases
end

#nameObject Also known as: table_name

Returns the value of attribute name



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

def name
  @name
end

#table_aliasObject

Returns the value of attribute table_alias



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

def table_alias
  @table_alias
end

Instance Method Details

#[](name) ⇒ Object



82
83
84
# File 'lib/arel/table.rb', line 82

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

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



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

def alias name = "#{self.name}_2"
  Nodes::TableAlias.new(self, name).tap do |node|
    @aliases << node
  end
end

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

Returns:

  • (Boolean)


93
94
95
96
97
98
# File 'lib/arel/table.rb', line 93

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

#fromObject



34
35
36
# File 'lib/arel/table.rb', line 34

def from
  SelectManager.new(self)
end

#group(*columns) ⇒ Object



54
55
56
# File 'lib/arel/table.rb', line 54

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

#hashObject



86
87
88
89
90
91
# File 'lib/arel/table.rb', line 86

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



78
79
80
# File 'lib/arel/table.rb', line 78

def having expr
  from.having expr
end

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



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

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



58
59
60
# File 'lib/arel/table.rb', line 58

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

#outer_join(relation) ⇒ Object



50
51
52
# File 'lib/arel/table.rb', line 50

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

#project(*things) ⇒ Object



66
67
68
# File 'lib/arel/table.rb', line 66

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

#skip(amount) ⇒ Object



74
75
76
# File 'lib/arel/table.rb', line 74

def skip amount
  from.skip amount
end

#take(amount) ⇒ Object



70
71
72
# File 'lib/arel/table.rb', line 70

def take amount
  from.take amount
end

#where(condition) ⇒ Object



62
63
64
# File 'lib/arel/table.rb', line 62

def where condition
  from.where condition
end