Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

where(foo: [1, nil]) becomes "WHERE foo = 1 OR foo IS NULL"

was "WHERE foo IN (1) OR foo IS NULL" before
  • Loading branch information...
commit 1877cf9b2a3e21bb77f33b28f9c42cc1071872a0 1 parent c8711e4
Akira Matsuda amatsuda authored
Showing with 4 additions and 1 deletion.
  1. +4 −1 activerecord/lib/active_record/relation/predicate_builder.rb
5 activerecord/lib/active_record/relation/predicate_builder.rb
View
@@ -29,8 +29,11 @@ def self.build_from_hash(engine, attributes, default_table)
if values.include?(nil)
values = values.compact
- if values.empty?
+ case values.length
+ when 0
array_predicates << attribute.eq(nil)
+ when 1
+ array_predicates << attribute.eq(values.first).or(attribute.eq(nil))
else
array_predicates << attribute.in(values).or(attribute.eq(nil))
end
Please sign in to comment.
Something went wrong with that request. Please try again.