aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/attributes/attribute.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-20 16:23:23 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-20 16:23:23 -0700
commit0e98ef149cd44dc04d40a8553e1743c5cb6d4a7c (patch)
treed81c026479834250149d90526c98247a1d004dd0 /lib/arel/attributes/attribute.rb
parentcd13c3e1dad07c1168a318feb543d3b1ede9f2cf (diff)
downloadrails-0e98ef149cd44dc04d40a8553e1743c5cb6d4a7c.tar.gz
rails-0e98ef149cd44dc04d40a8553e1743c5cb6d4a7c.tar.bz2
rails-0e98ef149cd44dc04d40a8553e1743c5cb6d4a7c.zip
supporting ranges for IN statements
Diffstat (limited to 'lib/arel/attributes/attribute.rb')
-rw-r--r--lib/arel/attributes/attribute.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/arel/attributes/attribute.rb b/lib/arel/attributes/attribute.rb
index 6bb880d211..e1f7fd81d2 100644
--- a/lib/arel/attributes/attribute.rb
+++ b/lib/arel/attributes/attribute.rb
@@ -12,10 +12,20 @@ module Arel
end
def in other
- if Arel::SelectManager === other
- other = other.to_a.map { |x| x.id }
+ case other
+ when Arel::SelectManager
+ Nodes::In.new self, other.to_a.map { |x| x.id }
+ when Range
+ if other.exclude_end?
+ left = Nodes::GreaterThanOrEqual.new(self, other.min)
+ right = Nodes::LessThan.new(self, other.max + 1)
+ Nodes::And.new left, right
+ else
+ Nodes::Between.new(self, Nodes::And.new(other.min, other.max))
+ end
+ else
+ Nodes::In.new self, other
end
- Nodes::In.new self, other
end
def gteq right