Created
May 9, 2013 15:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A sample Gemfile | |
source "https://rubygems.org" | |
gem 'data_mapper' | |
gem 'dm-sqlite-adapter' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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