#561 ✓resolved
Alex Arnell

exclusive ranges should respected

Reported by Alex Arnell | September 11th, 2008 @ 03:15 PM

ActiveRecord had this problem too. When you specify a range, it would blindly use some kind of `property` BETWEEN ? and ? query.

DataMapper should be able to tell the difference between inclusive and exclusive ranges.

require 'rubygems'
require 'dm-core'

# An in-memory Sqlite3 connection:
DataMapper.setup(:default, 'sqlite3::memory:')

class Category
  include DataMapper::Resource
  property :id,         Integer, :serial => true
  property :name,       String


(1..10).each do |i|
  Category.create(:id => i, :name => "category #{i}")

retval = Category.all(:id => 2..5)
puts 'size:', retval.size #=> should be 4
puts 'ids', retval.map { |c| c.id }.inspect #> should be [2, 3, 4, 5]

retval = Category.all(:id => 2...5)
puts 'size:', retval.size #=> should be 3
puts 'ids', retval.map { |c| c.id }.inspect #> should be [2, 3, 4]

I have attached a patch adjusting the specs to assert this behavior. I would fix the issue myself, but I'm not sure where the query conditions are transformed. I tracked it a little and from what I can tell it happens at the adapter level.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket


Referenced by