aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSven Fuchs <svenfuchs@artweb-design.de>2010-12-07 10:05:42 +0100
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-07 10:48:24 -0800
commit16ee8f66bcc527406e44c28a441e8f25481c5a0d (patch)
tree9ab0a6549a8c4c8af7bf911fa1ec326e6e8c95cb /lib
parent1c0d8c980c3b528ce2aeb0a528590822a31b5ef2 (diff)
downloadrails-16ee8f66bcc527406e44c28a441e8f25481c5a0d.tar.gz
rails-16ee8f66bcc527406e44c28a441e8f25481c5a0d.tar.bz2
rails-16ee8f66bcc527406e44c28a441e8f25481c5a0d.zip
implementation for passing a subquery to #in and #not_in
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/predications.rb4
-rw-r--r--lib/arel/visitors/to_sql.rb18
2 files changed, 12 insertions, 10 deletions
diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb
index 5a5c3d4495..dec4392f0f 100644
--- a/lib/arel/predications.rb
+++ b/lib/arel/predications.rb
@@ -31,7 +31,7 @@ module Arel
def in other
case other
when Arel::SelectManager
- Nodes::In.new self, other.to_a.map { |x| x.id }
+ Arel::Nodes::In.new(self, other)
when Range
if other.exclude_end?
left = Nodes::GreaterThanOrEqual.new(self, other.begin)
@@ -56,7 +56,7 @@ module Arel
def not_in other
case other
when Arel::SelectManager
- Nodes::NotIn.new self, other.to_a.map { |x| x.id }
+ Arel::Nodes::NotIn.new(self, other)
when Range
if other.exclude_end?
left = Nodes::LessThan.new(self, other.begin)
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 2fb464b265..6fc206c12c 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -72,6 +72,10 @@ module Arel
}.join ', '})"
end
+ def visit_Arel_SelectManager o
+ o.to_sql
+ end
+
def visit_Arel_Nodes_SelectStatement o
[
o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
@@ -204,17 +208,11 @@ module Arel
end
def visit_Arel_Nodes_In o
- right = o.right
- "#{visit o.left} IN (#{
- right.empty? ? 'NULL' : right.map { |x| visit x }.join(', ')
- })"
+ "#{visit o.left} IN (#{visit o.right})"
end
def visit_Arel_Nodes_NotIn o
- right = o.right
- "#{visit o.left} NOT IN (#{
- right.empty? ? 'NULL' : right.map { |x| visit x }.join(', ')
- })"
+ "#{visit o.left} NOT IN (#{visit o.right})"
end
def visit_Arel_Nodes_And o
@@ -291,6 +289,10 @@ module Arel
alias :visit_ActiveSupport_StringInquirer :visit_String
alias :visit_Class :visit_String
+ def visit_Array o
+ o.empty? ? 'NULL' : o.map { |x| visit x }.join(', ')
+ end
+
def quote value, column = nil
@connection.quote value, column
end