Permalink
Browse files

Merge pull request #4213 from amatsuda/ar_where_array_of_nil_and_a_value

AR#where with an Array of 2 elements including a nil
  • Loading branch information...
2 parents 0d01e09 + 1877cf9 commit 16381289c6fc40ac467928a7349a78403d49df47 @jonleighton jonleighton committed Dec 28, 2011
Showing with 5 additions and 2 deletions.
  1. +5 −2 activerecord/lib/active_record/relation/predicate_builder.rb
@@ -29,10 +29,13 @@ 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.compact).or(attribute.eq(nil))
+ array_predicates << attribute.in(values).or(attribute.eq(nil))
end
else
array_predicates << attribute.in(values)

0 comments on commit 1638128

Please sign in to comment.