Skip to content
Browse files

implementation for passing a subquery to #in and #not_in

  • Loading branch information...
1 parent 1c0d8c9 commit 16ee8f66bcc527406e44c28a441e8f25481c5a0d @svenfuchs svenfuchs committed with tenderlove Dec 7, 2010
Showing with 12 additions and 10 deletions.
  1. +2 −2 lib/arel/predications.rb
  2. +10 −8 lib/arel/visitors/to_sql.rb
View
4 lib/arel/predications.rb
@@ -31,7 +31,7 @@ def eq_all others
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 @@ def in_all others
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)
View
18 lib/arel/visitors/to_sql.rb
@@ -72,6 +72,10 @@ def visit_Arel_Nodes_Values o
}.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 @@ def visit_Arel_Table o
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 @@ def visit_String o; quote(o, @last_column) end
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

0 comments on commit 16ee8f6

Please sign in to comment.
Something went wrong with that request. Please try again.