Permalink
Browse files

Generate more sqlish queue.

Now, instead of the following SQL code:
  some_field IN (1, 2, NULL)

Arel will generate the proper one:
  some_field IN (1, 2) OR IS NULL
  • Loading branch information...
1 parent 2b27e65 commit fe5719fea54468f0ebcc97060df6958db17303de @gmile gmile committed Mar 24, 2011
Showing with 11 additions and 1 deletion.
  1. +11 −1 lib/arel/predications.rb
View
@@ -41,7 +41,17 @@ def in other
Nodes::Between.new(self, Nodes::And.new([other.begin, other.end]))
end
else
- Nodes::In.new self, other
+ if other.include?(nil)
+ if other.size > 1
+ set = Nodes::In.new self, other.compact
+ null = Nodes::Equality.new self, nil
+ Nodes::Or.new set, null
+ else
+ Nodes::Equality.new self, nil
+ end
+ else
+ Nodes::In.new self, other
+ end
end
end

0 comments on commit fe5719f

Please sign in to comment.