diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-11-16 09:26:02 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-11-16 09:26:02 -0800 |
commit | 936404399d0bc4b7100b7837676c34f8130d565d (patch) | |
tree | 148fa360e845374b988f4419d6a8b55c225fb4bf /activerecord/lib | |
parent | 8d1a2b3ecde5a8745b3eaab4763a71d80ca3441f (diff) | |
parent | 63a22ca6169f06d10cd843ea3a75df6498fdcf7d (diff) | |
download | rails-936404399d0bc4b7100b7837676c34f8130d565d.tar.gz rails-936404399d0bc4b7100b7837676c34f8130d565d.tar.bz2 rails-936404399d0bc4b7100b7837676c34f8130d565d.zip |
Merge pull request #3634 from RyanNaughton/fixes_3483
Fixes 3483
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder.rb | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 7e8ddd1b5d..af167dc59b 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -22,21 +22,23 @@ module ActiveRecord value = value.select(value.klass.arel_table[value.klass.primary_key]) if value.select_values.empty? attribute.in(value.arel.ast) when Array, ActiveRecord::Associations::CollectionProxy - values = value.to_a.map { |x| - x.is_a?(ActiveRecord::Base) ? x.id : x - } + values = value.to_a.map {|x| x.is_a?(ActiveRecord::Base) ? x.id : x} + ranges, values = values.partition {|value| value.is_a?(Range) || value.is_a?(Arel::Relation)} + + array_predicates = ranges.map {|range| attribute.in(range)} if values.include?(nil) values = values.compact if values.empty? - attribute.eq nil + array_predicates << attribute.eq(nil) else - attribute.in(values.compact).or attribute.eq(nil) + array_predicates << attribute.in(values.compact).or(attribute.eq(nil)) end else - attribute.in(values) + array_predicates << attribute.in(values) end + array_predicates.inject {|composite, predicate| composite.or(predicate)} when Range, Arel::Relation attribute.in(value) when ActiveRecord::Base |