Module: Arel::Relation
- Includes:
- Enumerable
- Defined in:
- lib/arel/algebra/relations/relation.rb
Defined Under Namespace
Classes: JoinOperation
Constant Summary collapse
- @@connection_tables_primary_keys =
{}
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #alias ⇒ Object
- #attributes ⇒ Object
- #bind(relation) ⇒ Object
- #call ⇒ Object
- #christener ⇒ Object
- #compiler ⇒ Object
- #delete ⇒ Object
- #each ⇒ Object
- #exclusion_predicate_sql ⇒ Object
- #externalizable? ⇒ Boolean
- #externalize ⇒ Object
- #find_attribute_matching_name(name) ⇒ Object
- #from(thing) ⇒ Object
- #from_clauses ⇒ Object
- #group_clauses ⇒ Object
- #groupings ⇒ Object
- #having_clauses ⇒ Object
- #havings ⇒ Object
- #inclusion_predicate_sql ⇒ Object
- #insert(record) ⇒ Object
- #inserts ⇒ Object
- #join(other_relation = nil, join_class = InnerJoin) ⇒ Object
- #join? ⇒ Boolean
-
#joins(formatter = nil) ⇒ Object
FIXME.
- #lock(locking = true) ⇒ Object
- #locked ⇒ Object
- #order_clauses ⇒ Object
- #orders ⇒ Object
- #outer_join(other_relation = nil) ⇒ Object
- #position_of(attribute) ⇒ Object
- #primary_key ⇒ Object
- #project(*args) ⇒ Object
- #projections ⇒ Object
- #select_clauses ⇒ Object
- #session ⇒ Object
- #skip(thing = nil) ⇒ Object
- #skipped ⇒ Object
- #sources ⇒ Object
- #take(count) ⇒ Object
- #taken ⇒ Object
- #to_sql(formatter = nil) ⇒ Object
- #update(assignments) ⇒ Object
- #where(clause = nil) ⇒ Object
- #where_clauses ⇒ Object
- #wheres ⇒ Object
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
7 8 9 |
# File 'lib/arel/algebra/relations/relation.rb', line 7 def count @count end |
Instance Method Details
#[](index) ⇒ Object
176 177 178 |
# File 'lib/arel/algebra/relations/relation.rb', line 176 def [](index) attributes[index] end |
#alias ⇒ Object
154 155 156 |
# File 'lib/arel/algebra/relations/relation.rb', line 154 def alias Alias.new(self) end |
#attributes ⇒ Object
192 |
# File 'lib/arel/algebra/relations/relation.rb', line 192 def attributes; Header.new end |
#bind(relation) ⇒ Object
21 22 23 |
# File 'lib/arel/algebra/relations/relation.rb', line 21 def bind(relation) self end |
#call ⇒ Object
17 18 19 |
# File 'lib/arel/algebra/relations/relation.rb', line 17 def call engine.read(self) end |
#christener ⇒ Object
48 49 50 |
# File 'lib/arel/algebra/relations/relation.rb', line 48 def christener @christener ||= Sql::Christener.new end |
#compiler ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/arel/algebra/relations/relation.rb', line 33 def compiler @compiler ||= begin Arel::SqlCompiler.const_get("#{engine.adapter_name}Compiler").new(self) rescue Arel::SqlCompiler::GenericCompiler.new(self) end end |
#delete ⇒ Object
166 167 168 |
# File 'lib/arel/algebra/relations/relation.rb', line 166 def delete session.delete Deletion.new(self) end |
#each ⇒ Object
101 102 103 |
# File 'lib/arel/algebra/relations/relation.rb', line 101 def each session.read(self).each { |e| yield e } end |
#exclusion_predicate_sql ⇒ Object
56 57 58 |
# File 'lib/arel/algebra/relations/relation.rb', line 56 def exclusion_predicate_sql "NOT IN" end |
#externalizable? ⇒ Boolean
29 30 31 |
# File 'lib/arel/algebra/relations/relation.rb', line 29 def externalizable? false end |
#externalize ⇒ Object
25 26 27 |
# File 'lib/arel/algebra/relations/relation.rb', line 25 def externalize @externalized ||= externalizable?? Externalization.new(self) : self end |
#find_attribute_matching_name(name) ⇒ Object
180 181 182 |
# File 'lib/arel/algebra/relations/relation.rb', line 180 def find_attribute_matching_name(name) attributes.detect { |a| a.named?(name) } || Attribute.new(self, name) end |
#from(thing) ⇒ Object
146 147 148 |
# File 'lib/arel/algebra/relations/relation.rb', line 146 def from thing From.new self, thing end |
#from_clauses ⇒ Object
81 82 83 |
# File 'lib/arel/algebra/relations/relation.rb', line 81 def from_clauses sources.empty? ? table_sql : sources end |
#group_clauses ⇒ Object
89 90 91 |
# File 'lib/arel/algebra/relations/relation.rb', line 89 def group_clauses groupings.collect { |g| g.to_sql(Sql::GroupClause.new(self)) } end |
#groupings ⇒ Object
197 |
# File 'lib/arel/algebra/relations/relation.rb', line 197 def groupings; [] end |
#having_clauses ⇒ Object
93 94 95 |
# File 'lib/arel/algebra/relations/relation.rb', line 93 def having_clauses havings.collect { |g| g.to_sql(Sql::HavingClause.new(self)) } end |
#havings ⇒ Object
198 |
# File 'lib/arel/algebra/relations/relation.rb', line 198 def havings; [] end |
#inclusion_predicate_sql ⇒ Object
52 53 54 |
# File 'lib/arel/algebra/relations/relation.rb', line 52 def inclusion_predicate_sql "IN" end |
#insert(record) ⇒ Object
158 159 160 |
# File 'lib/arel/algebra/relations/relation.rb', line 158 def insert(record) session.create Insert.new(self, record) end |
#inserts ⇒ Object
196 |
# File 'lib/arel/algebra/relations/relation.rb', line 196 def inserts; [] end |
#join(other_relation = nil, join_class = InnerJoin) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/arel/algebra/relations/relation.rb', line 105 def join(other_relation = nil, join_class = InnerJoin) case other_relation when String StringJoin.new(self, other_relation) when Relation JoinOperation.new(join_class, self, other_relation) else self end end |
#join? ⇒ Boolean
13 14 15 |
# File 'lib/arel/algebra/relations/relation.rb', line 13 def join? false end |
#joins(formatter = nil) ⇒ Object
FIXME
199 |
# File 'lib/arel/algebra/relations/relation.rb', line 199 def joins(formatter = nil); nil end |
#lock(locking = true) ⇒ Object
150 151 152 |
# File 'lib/arel/algebra/relations/relation.rb', line 150 def lock(locking = true) Lock.new(self, locking) end |
#locked ⇒ Object
203 |
# File 'lib/arel/algebra/relations/relation.rb', line 203 def locked; [] end |
#order_clauses ⇒ Object
97 98 99 |
# File 'lib/arel/algebra/relations/relation.rb', line 97 def order_clauses orders.collect { |o| o.to_sql(Sql::OrderClause.new(self)) } end |
#orders ⇒ Object
195 |
# File 'lib/arel/algebra/relations/relation.rb', line 195 def orders; [] end |
#outer_join(other_relation = nil) ⇒ Object
116 117 118 |
# File 'lib/arel/algebra/relations/relation.rb', line 116 def outer_join(other_relation = nil) join(other_relation, OuterJoin) end |
#position_of(attribute) ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/arel/algebra/relations/relation.rb', line 184 def position_of(attribute) @position_of ||= {} return @position_of[attribute] if @position_of.key? attribute @position_of[attribute] = attributes.index(attributes[attribute]) end |
#primary_key ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/arel/algebra/relations/relation.rb', line 60 def primary_key connection_id = engine.connection.object_id if @@connection_tables_primary_keys[connection_id] && @@connection_tables_primary_keys[connection_id].has_key?(table.name) @@connection_tables_primary_keys[connection_id][table.name] else @@connection_tables_primary_keys[connection_id] ||= {} @@connection_tables_primary_keys[connection_id][table.name] = engine.connection.primary_key(table.name) end end |
#project(*args) ⇒ Object
130 131 132 |
# File 'lib/arel/algebra/relations/relation.rb', line 130 def project *args args.empty? ? self : Project.new(self, args) end |
#projections ⇒ Object
193 |
# File 'lib/arel/algebra/relations/relation.rb', line 193 def projections; [] end |
#select_clauses ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/arel/algebra/relations/relation.rb', line 70 def select_clauses attributes.map { |a| case a when Value a.value else a.to_sql(Sql::SelectClause.new(self)) end } end |
#session ⇒ Object
9 10 11 |
# File 'lib/arel/algebra/relations/relation.rb', line 9 def session Session.instance end |
#skip(thing = nil) ⇒ Object
138 139 140 |
# File 'lib/arel/algebra/relations/relation.rb', line 138 def skip thing = nil thing ? Skip.new(self, thing) : self end |
#skipped ⇒ Object
201 |
# File 'lib/arel/algebra/relations/relation.rb', line 201 def skipped; nil end |
#sources ⇒ Object
202 |
# File 'lib/arel/algebra/relations/relation.rb', line 202 def sources; [] end |
#take(count) ⇒ Object
142 143 144 |
# File 'lib/arel/algebra/relations/relation.rb', line 142 def take count Take.new self, count end |
#taken ⇒ Object
200 |
# File 'lib/arel/algebra/relations/relation.rb', line 200 def taken; nil end |
#to_sql(formatter = nil) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/arel/algebra/relations/relation.rb', line 41 def to_sql(formatter = nil) sql = compiler.select_sql return sql unless formatter formatter.select sql, self end |
#update(assignments) ⇒ Object
162 163 164 |
# File 'lib/arel/algebra/relations/relation.rb', line 162 def update(assignments) session.update Update.new(self, assignments) end |
#where(clause = nil) ⇒ Object
134 135 136 |
# File 'lib/arel/algebra/relations/relation.rb', line 134 def where clause = nil clause ? Where.new(self, [clause].flatten) : self end |
#where_clauses ⇒ Object
85 86 87 |
# File 'lib/arel/algebra/relations/relation.rb', line 85 def where_clauses wheres.map { |w| w.value } end |
#wheres ⇒ Object
194 |
# File 'lib/arel/algebra/relations/relation.rb', line 194 def wheres; [] end |