Skip to content

Instantly share code, notes, and snippets.

@guiman
Created May 9, 2013 15:01
Show Gist options
  • Save guiman/5548007 to your computer and use it in GitHub Desktop.
Save guiman/5548007 to your computer and use it in GitHub Desktop.
Well I think there is something wrong with DataMapper::Collection slice, when mixing queries and slices. Any thoughts? I'm working on what seems to be an issue
# A sample Gemfile
source "https://rubygems.org"
gem 'data_mapper'
gem 'dm-sqlite-adapter'
require 'bundler'
Bundler.require
DataMapper.setup :default, 'sqlite:///tmp/project.db'
class Person
include DataMapper::Resource
property :id, Serial
property :age, String
end
DataMapper.auto_migrate!
Person.create age: 1
Person.create age: 2
Person.create age: 3
Person.create age: 4
Person.create age: 5
Person.create age: 6
Person[0..3] # this should include Person instances with age 1, 2 and 3
person = Person[0..3] #his should also include the same people
Person[0..3].all :age.gt => 2 # This must return the person with age 3
# => [#<Person @id=3 @age="3">, #<Person @id=4 @age="4">, #<Person @id=5 @age="5">, #<Person @id=6 @age="6">]
person.all :age.gt => 2 # Well check out what returns
# => [#<Person @id=3 @age="3">, #<Person @id=4 @age="4">]
# Any thoughts on that?
# But the problem goes even further
Person[0..3][1..1].all :age.gt => 2
# => [#<Person @id=4 @age="4">]
person[1..1].all :age.gt => 2
# => []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment