Permalink
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...
1 parent c8711e4 commit 1877cf9b2a3e21bb77f33b28f9c42cc1071872a0 @amatsuda amatsuda committed Dec 28, 2011
Showing with 4 additions and 1 deletion.
  1. +4 −1 activerecord/lib/active_record/relation/predicate_builder.rb
@@ -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

1 comment on commit 1877cf9

Very nice!

I'm quite sure I'll forget about this by the time I would need it, though;-) Could you add some words to the CHANGELOG so people notice this little gem?

Please sign in to comment.