aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
diff options
context:
space:
mode:
authorRyan Naughton <Ryan.J.Naughton@gmail.com>2011-11-14 21:43:27 -0600
committerRyan Naughton <Ryan.J.Naughton@gmail.com>2011-11-14 21:43:27 -0600
commit63a22ca6169f06d10cd843ea3a75df6498fdcf7d (patch)
treee0dac46ef7ca2dc0f6b66ff480e0099995bbc2a6 /activerecord/lib/active_record/relation
parente1b79c56bef43d858fc59dbe7506039414c9e4ed (diff)
downloadrails-63a22ca6169f06d10cd843ea3a75df6498fdcf7d.tar.gz
rails-63a22ca6169f06d10cd843ea3a75df6498fdcf7d.tar.bz2
rails-63a22ca6169f06d10cd843ea3a75df6498fdcf7d.zip
Fixes issue #3483, regarding using a mixture of ranges and discrete values in find conditions. Paired with Joey Schoblaska.
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb14
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