Skip to content
This repository
Browse code

implementation for passing a subquery to #in and #not_in

  • Loading branch information...
commit 1135c2c0884bfddffa39b784d71cd3fb22bd8988 1 parent 54d62de
Sven Fuchs svenfuchs authored

Showing 2 changed files with 12 additions and 10 deletions. Show diff stats Hide diff stats

  1. +2 2 lib/arel/predications.rb
  2. +10 8 lib/arel/visitors/to_sql.rb
4 lib/arel/predications.rb
@@ -31,7 +31,7 @@ def eq_all others
31 31 def in other
32 32 case other
33 33 when Arel::SelectManager
34   - Nodes::In.new self, other.to_a.map { |x| x.id }
  34 + Arel::Nodes::In.new(self, other)
35 35 when Range
36 36 if other.exclude_end?
37 37 left = Nodes::GreaterThanOrEqual.new(self, other.begin)
@@ -56,7 +56,7 @@ def in_all others
56 56 def not_in other
57 57 case other
58 58 when Arel::SelectManager
59   - Nodes::NotIn.new self, other.to_a.map { |x| x.id }
  59 + Arel::Nodes::NotIn.new(self, other)
60 60 when Range
61 61 if other.exclude_end?
62 62 left = Nodes::LessThan.new(self, other.begin)
18 lib/arel/visitors/to_sql.rb
@@ -101,6 +101,10 @@ def visit_Arel_Nodes_Values o
101 101 }.join ', '})"
102 102 end
103 103
  104 + def visit_Arel_SelectManager o
  105 + o.to_sql
  106 + end
  107 +
104 108 def visit_Arel_Nodes_SelectStatement o
105 109 [
106 110 o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
@@ -233,17 +237,11 @@ def visit_Arel_Table o
233 237 end
234 238
235 239 def visit_Arel_Nodes_In o
236   - right = o.right
237   - "#{visit o.left} IN (#{
238   - right.empty? ? 'NULL' : right.map { |x| visit x }.join(', ')
239   - })"
  240 + "#{visit o.left} IN (#{visit o.right})"
240 241 end
241 242
242 243 def visit_Arel_Nodes_NotIn o
243   - right = o.right
244   - "#{visit o.left} NOT IN (#{
245   - right.empty? ? 'NULL' : right.map { |x| visit x }.join(', ')
246   - })"
  244 + "#{visit o.left} NOT IN (#{visit o.right})"
247 245 end
248 246
249 247 def visit_Arel_Nodes_And o
@@ -320,6 +318,10 @@ def visit_String o; quote(o, @last_column) end
320 318 alias :visit_ActiveSupport_StringInquirer :visit_String
321 319 alias :visit_Class :visit_String
322 320
  321 + def visit_Array o
  322 + o.empty? ? 'NULL' : o.map { |x| visit x }.join(', ')
  323 + end
  324 +
323 325 def quote value, column = nil
324 326 @connection.quote value, column
325 327 end

0 comments on commit 1135c2c

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