
:offset flag requires :limit to be set, even when using Model.first
Reported by Ted Han (knowtheory) | July 2nd, 2009 @ 12:56 PM | in 0.10.0
require 'dm-core'
DataMapper.setup(:default,:adapter=>"in_memory");
class Taco
include DataMapper::Resource
property :id, Serial
end
Taco.first(:offset=>2)
produces this error:
ArgumentError: +options[:offset]+ cannot be greater than 0 if limit is not specified
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:796:in assert_valid_offset'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:664:in assert_valid_options'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:659:in each'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:659:in assert_valid_options'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:601:in initialize'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:307:in update'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:323:in merge'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model.rb:615:in scoped_query'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model.rb:254:in first'
from (irb):3
The issue here, is that while the Model.first method does merge {:limit => 1} into the query, it does it after DM tries to cast {:offset=>3} into a Query, and explodes because a :limit has not been set.
So either DM's strictures on :offset in Query need to be loosened, or :limit => needs to be merged into the args hash for Model.first prior to trying to cast the args as a Query.
Comments and changes to this ticket
-
Dan Kubb (dkubb) July 2nd, 2009 @ 01:46 PM
- State changed from unconfirmed to accepted
After reviewing the code I can confirm this is an issue.
This error probably would've been caught sooner had the finder specs for Collection been extracted into a shared spec and used to test Model and Collection.
Rather than write a failing spec for Model that duplicates this problem, I will extract the shared specs first, and then work to make them pass, which will resolve this ticket.
-
Ted Han (knowtheory) July 2nd, 2009 @ 06:01 PM
dkubb, regarding whether this is a problem for both Collection and Model, it appears that this is only an issue with Model.
-
Dan Kubb (dkubb) July 16th, 2009 @ 03:29 AM
- State changed from accepted to resolved
(from [95de3e8590094a6b95de772cb443956edac355ea]) Fixed bug in Model#first preventing :offset from being used
[#944 state:resolved] http://github.com/datamapper/dm-core/commit/95de3e8590094a6b95de772...
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.
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
-
944 :offset flag requires :limit to be set, even when using Model.first [#944 state:resolved] http://github.com/datamapper/dm-co...