diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-28 07:50:25 -0800 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-28 07:50:25 -0800 |
commit | 16381289c6fc40ac467928a7349a78403d49df47 (patch) | |
tree | 4ae8bb62c797adf6df73c71fe34b4318980cc70b | |
parent | 0d01e09c6c78c2276433e69671af5c211e243d50 (diff) | |
parent | 1877cf9b2a3e21bb77f33b28f9c42cc1071872a0 (diff) | |
download | rails-16381289c6fc40ac467928a7349a78403d49df47.tar.gz rails-16381289c6fc40ac467928a7349a78403d49df47.tar.bz2 rails-16381289c6fc40ac467928a7349a78403d49df47.zip |
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
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index eee198e760..95b6efb402 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -29,10 +29,13 @@ module ActiveRecord 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) |