Class: Arel::Table
- Inherits:
-
Object
show all
- Includes:
- Crud, FactoryMethods
- Defined in:
- lib/arel/table.rb
Class Attribute Summary (collapse)
Instance Attribute Summary (collapse)
Instance Method Summary
(collapse)
#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, #delete, #insert, #update
Constructor Details
- (Table) initialize(name, engine = Table.engine)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/arel/table.rb', line 14
def initialize name, engine = Table.engine
@name = name.to_s
@engine = engine
@columns = nil
@aliases = []
@table_alias = nil
@primary_key = nil
if Hash === engine
@engine = engine[:engine] || Table.engine
@table_alias = engine[:as] unless engine[:as].to_s == @name
end
end
|
Class Attribute Details
+ (Object) engine
Returns the value of attribute engine
7
8
9
|
# File 'lib/arel/table.rb', line 7
def engine
@engine
end
|
Instance Attribute Details
- (Object) aliases
Returns the value of attribute aliases
9
10
11
|
# File 'lib/arel/table.rb', line 9
def aliases
@aliases
end
|
- (Object) engine
Returns the value of attribute engine
9
10
11
|
# File 'lib/arel/table.rb', line 9
def engine
@engine
end
|
- (Object) name
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
|
- (Object) table_alias
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
- (Object) [](name)
114
115
116
|
# File 'lib/arel/table.rb', line 114
def [] name
::Arel::Attribute.new self, name
end
|
- (Object) alias(name = "#{self.name}_2")
45
46
47
48
49
|
# File 'lib/arel/table.rb', line 45
def alias name = "#{self.name}_2"
Nodes::TableAlias.new(self, name).tap do |node|
@aliases << node
end
end
|
- (Object) columns
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/arel/table.rb', line 103
def columns
if $VERBOSE
warn <<-eowarn
(#{caller.first}) Arel::Table#columns is deprecated and will be removed in
Arel 4.0.0 with no replacement. PEW PEW PEW!!!
eowarn
end
@columns ||=
attributes_for @engine.connection.columns(@name, "#{@name} Columns")
end
|
- (Object) from(table)
51
52
53
|
# File 'lib/arel/table.rb', line 51
def from table
SelectManager.new(@engine, table)
end
|
- (Object) group(*columns)
75
76
77
|
# File 'lib/arel/table.rb', line 75
def group *columns
from(self).group(*columns)
end
|
- (Object) having(expr)
99
100
101
|
# File 'lib/arel/table.rb', line 99
def having expr
from(self).having expr
end
|
- (Object) insert_manager
122
123
124
|
# File 'lib/arel/table.rb', line 122
def insert_manager
InsertManager.new(@engine)
end
|
- (Object) join(relation, klass = Nodes::InnerJoin)
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/arel/table.rb', line 63
def join relation, klass = Nodes::InnerJoin
return from(self) unless relation
case relation
when String, Nodes::SqlLiteral
raise if relation.blank?
klass = Nodes::StringJoin
end
from(self).join(relation, klass)
end
|
- (Object) joins(manager)
55
56
57
58
59
60
61
|
# File 'lib/arel/table.rb', line 55
def joins manager
if $VERBOSE
warn "joins is deprecated and will be removed in 4.0.0"
warn "please remove your call to joins from #{caller.first}"
end
nil
end
|
- (Object) order(*expr)
79
80
81
|
# File 'lib/arel/table.rb', line 79
def order *expr
from(self).order(*expr)
end
|
- (Object) primary_key
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/arel/table.rb', line 32
def primary_key
if $VERBOSE
warn <<-eowarn
primary_key (#{caller.first}) is deprecated and will be removed in ARel 4.0.0
eowarn
end
@primary_key ||= begin
primary_key_name = @engine.connection.primary_key(name)
primary_key_name && self[primary_key_name]
end
end
|
- (Object) project(*things)
87
88
89
|
# File 'lib/arel/table.rb', line 87
def project *things
from(self).project(*things)
end
|
- (Object) select_manager
118
119
120
|
# File 'lib/arel/table.rb', line 118
def select_manager
SelectManager.new(@engine)
end
|
- (Object) skip(amount)
95
96
97
|
# File 'lib/arel/table.rb', line 95
def skip amount
from(self).skip amount
end
|
- (Object) take(amount)
91
92
93
|
# File 'lib/arel/table.rb', line 91
def take amount
from(self).take amount
end
|
- (Object) where(condition)
83
84
85
|
# File 'lib/arel/table.rb', line 83
def where condition
from(self).where condition
end
|