Skip to content

Commit

Permalink
Handle ranges with excluded end.
Browse files Browse the repository at this point in the history
  • Loading branch information
miloops committed Mar 29, 2010
1 parent aa9559c commit 233ee77
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/arel/algebra/attributes/attribute.rb
Expand Up @@ -111,7 +111,11 @@ def matches(regexp)
end

def in(array)
Predicates::In.new(self, array)
if array.is_a?(Range) && array.exclude_end?
[Predicates::GreaterThanOrEqualTo.new(self, array.begin), Predicates::LessThan.new(self, array.end)]
else
Predicates::In.new(self, array)
end
end
end
include Predications
Expand Down

2 comments on commit 233ee77

@sdsykes
Copy link

@sdsykes sdsykes commented on 233ee77 Apr 6, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be better to continue to use BETWEEN for a range with an excluded end?
So move this fix to engines/sql/core_extensions/range.rb ?

@dkubb
Copy link

@dkubb dkubb commented on 233ee77 Apr 6, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdsykes: In SQL a BETWEEN clause is inclusive (it matches the start/end values). An exclusive Range does not match the end value. For example try (1...100).include?(100) from IRB and you'll see that it returns false, while (1..100).include?(100) returns true.

Please sign in to comment.