#944 ✓resolved
Ted Han (knowtheory)

: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'


class Taco
  include DataMapper::Resource
  property :id, Serial


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

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