aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/crud.rb1
-rw-r--r--lib/arel/nodes.rb2
-rw-r--r--lib/arel/nodes/inner_join.rb9
-rw-r--r--lib/arel/nodes/join.rb13
-rw-r--r--lib/arel/nodes/outer_join.rb6
-rw-r--r--lib/arel/select_manager.rb13
-rw-r--r--lib/arel/visitors/to_sql.rb4
7 files changed, 36 insertions, 12 deletions
diff --git a/lib/arel/crud.rb b/lib/arel/crud.rb
index 6861ff016c..2bf5f85823 100644
--- a/lib/arel/crud.rb
+++ b/lib/arel/crud.rb
@@ -7,6 +7,7 @@ module Arel
um = UpdateManager.new @engine
if String === values
+ values = SqlLiteral.new values
um.table @ctx.froms.last
else
um.table values.first.first.relation
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb
index 7183a60591..67568b5fd4 100644
--- a/lib/arel/nodes.rb
+++ b/lib/arel/nodes.rb
@@ -11,5 +11,7 @@ require 'arel/nodes/update_statement'
require 'arel/nodes/delete_statement'
require 'arel/nodes/unqualified_column'
require 'arel/nodes/table_alias'
+require 'arel/nodes/join'
require 'arel/nodes/inner_join'
+require 'arel/nodes/outer_join'
require 'arel/nodes/on'
diff --git a/lib/arel/nodes/inner_join.rb b/lib/arel/nodes/inner_join.rb
index a39ded9f1c..bf10eeac18 100644
--- a/lib/arel/nodes/inner_join.rb
+++ b/lib/arel/nodes/inner_join.rb
@@ -1,13 +1,6 @@
module Arel
module Nodes
- class InnerJoin
- attr_accessor :left, :right, :constraint
-
- def initialize left, right, constraint
- @left = left
- @right = right
- @constraint = constraint
- end
+ class InnerJoin < Arel::Nodes::Join
end
end
end
diff --git a/lib/arel/nodes/join.rb b/lib/arel/nodes/join.rb
new file mode 100644
index 0000000000..6dede632c5
--- /dev/null
+++ b/lib/arel/nodes/join.rb
@@ -0,0 +1,13 @@
+module Arel
+ module Nodes
+ class Join
+ attr_accessor :left, :right, :constraint
+
+ def initialize left, right, constraint
+ @left = left
+ @right = right
+ @constraint = constraint
+ end
+ end
+ end
+end
diff --git a/lib/arel/nodes/outer_join.rb b/lib/arel/nodes/outer_join.rb
new file mode 100644
index 0000000000..bea5578b95
--- /dev/null
+++ b/lib/arel/nodes/outer_join.rb
@@ -0,0 +1,6 @@
+module Arel
+ module Nodes
+ class OuterJoin < Arel::Nodes::Join
+ end
+ end
+end
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index 533911e635..462b0765a5 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -19,10 +19,6 @@ module Arel
end
def project projection
- projection = ::String == projection.class ?
- Nodes::SqlLiteral.new(projection) :
- projection
-
@ctx.projections << projection
self
end
@@ -40,5 +36,14 @@ module Arel
@head.limit = limit
self
end
+
+ def join_sql
+ viz = Visitors::ToSql.new @engine
+ @ctx.froms.grep(Nodes::Join).map { |x| viz.accept x }.join ', '
+ end
+
+ def joins manager
+ manager.join_sql
+ end
end
end
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 3b0a0dc5df..401bdb3255 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -61,6 +61,10 @@ module Arel
"#{visit o.relation} #{quote_table_name o.name}"
end
+ def visit_Arel_Nodes_OuterJoin o
+ "#{visit o.left} OUTER JOIN #{visit o.right} #{visit o.constraint}"
+ end
+
def visit_Arel_Nodes_InnerJoin o
"#{visit o.left} INNER JOIN #{visit o.right} #{visit o.constraint}"
end