aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/crud.rb4
-rw-r--r--lib/arel/nodes/select_core.rb4
-rw-r--r--lib/arel/select_manager.rb14
-rw-r--r--lib/arel/visitors/join_sql.rb2
-rw-r--r--lib/arel/visitors/to_sql.rb2
5 files changed, 13 insertions, 13 deletions
diff --git a/lib/arel/crud.rb b/lib/arel/crud.rb
index 196dc56554..e060a82941 100644
--- a/lib/arel/crud.rb
+++ b/lib/arel/crud.rb
@@ -7,7 +7,7 @@ module Arel
um = UpdateManager.new @engine
if Nodes::SqlLiteral === values
- relation = @ctx.froms.last
+ relation = @ctx.froms
else
relation = values.first.first.relation
end
@@ -37,7 +37,7 @@ module Arel
def delete
dm = DeleteManager.new @engine
dm.wheres = @ctx.wheres
- dm.from @ctx.froms.last
+ dm.from @ctx.froms
@engine.connection.delete dm.to_sql, 'AREL'
end
end
diff --git a/lib/arel/nodes/select_core.rb b/lib/arel/nodes/select_core.rb
index bd85dad24a..42e590ce36 100644
--- a/lib/arel/nodes/select_core.rb
+++ b/lib/arel/nodes/select_core.rb
@@ -5,7 +5,7 @@ module Arel
attr_accessor :having
def initialize
- @froms = []
+ @froms = nil
@projections = []
@wheres = []
@groups = []
@@ -14,7 +14,7 @@ module Arel
def initialize_copy other
super
- @froms = @froms.clone
+ @froms = @froms.clone if @froms
@projections = @projections.clone
@wheres = @wheres.clone
@group = @groups.clone
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index 98d9385b0a..4866ea66c9 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -39,7 +39,7 @@ module Arel
end
def on *exprs
- @ctx.froms.last.constraint = Nodes::On.new(collapse(exprs))
+ @ctx.froms.constraint = Nodes::On.new(collapse(exprs))
self
end
@@ -59,8 +59,8 @@ module Arel
# FIXME: this is a hack to support
# test_with_two_tables_in_from_without_getting_double_quoted
# from the AR tests.
- unless @ctx.froms.empty?
- source = @ctx.froms.first
+ if @ctx.froms
+ source = @ctx.froms
if Nodes::SqlLiteral === table && Nodes::Join === source
source.left = table
@@ -68,7 +68,7 @@ module Arel
end
end
- @ctx.froms = [table]
+ @ctx.froms = table
self
end
@@ -78,9 +78,9 @@ module Arel
case relation
when String, Nodes::SqlLiteral
raise if relation.blank?
- from Nodes::StringJoin.new(@ctx.froms.pop, relation)
+ from Nodes::StringJoin.new(@ctx.froms, relation)
else
- from klass.new(@ctx.froms.pop, relation, nil)
+ from klass.new(@ctx.froms, relation, nil)
end
end
@@ -162,7 +162,7 @@ module Arel
# FIXME: this method should go away
def insert values
im = InsertManager.new @engine
- im.into @ctx.froms.last
+ im.into @ctx.froms
im.insert values
@engine.connection.insert im.to_sql
end
diff --git a/lib/arel/visitors/join_sql.rb b/lib/arel/visitors/join_sql.rb
index 099e78b692..49625e850d 100644
--- a/lib/arel/visitors/join_sql.rb
+++ b/lib/arel/visitors/join_sql.rb
@@ -10,7 +10,7 @@ module Arel
# compatibility with Arel V1.0
class JoinSql < Arel::Visitors::ToSql
def visit_Arel_Nodes_SelectCore o
- o.froms.grep(Nodes::Join).map { |x| visit x }.join ', '
+ [o.froms].grep(Nodes::Join).map { |x| visit x }.join ', '
end
def visit_Arel_Nodes_StringJoin o
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index d3da65b425..9186d28566 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -64,7 +64,7 @@ module Arel
def visit_Arel_Nodes_SelectCore o
[
"SELECT #{o.projections.map { |x| visit x }.join ', '}",
- ("FROM #{o.froms.map { |x| visit x }.join ', ' }" unless o.froms.empty?),
+ ("FROM #{visit o.froms}" if o.froms),
("WHERE #{o.wheres.map { |x| visit x }.join ' AND ' }" unless o.wheres.empty?),
("GROUP BY #{o.groups.map { |x| visit x }.join ', ' }" unless o.groups.empty?),
(visit(o.having) if o.having),