diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-04-29 11:01:59 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-04-29 11:01:59 -0700 |
commit | 850b3ca4779da201d4805a12fe29d9d9a491739e (patch) | |
tree | 438cede35a48ba1be74f4322d8df01a22416592f /activerecord/lib | |
parent | 66a18855eafa71c11a37333ce1314889cbd0f742 (diff) | |
download | rails-850b3ca4779da201d4805a12fe29d9d9a491739e.tar.gz rails-850b3ca4779da201d4805a12fe29d9d9a491739e.tar.bz2 rails-850b3ca4779da201d4805a12fe29d9d9a491739e.zip |
supporting nil when passed in as an IN clause
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 982b3d7e9f..2814771002 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -25,7 +25,18 @@ module ActiveRecord values = value.to_a.map { |x| x.is_a?(ActiveRecord::Base) ? x.id : x } - attribute.in(values) + + if values.include?(nil) + values = values.compact + if values.empty? + attribute.eq nil + else + attribute.in(values.compact).or attribute.eq(nil) + end + else + attribute.in(values) + end + when Range, Arel::Relation attribute.in(value) when ActiveRecord::Base |