Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Missing Info for ActiveRecord::Base#find option ':offset'

#2191

This evening I was tripped up by the way :offset works in ActiveRecord::Base#find. I was under the impression that you could just specify an offset and get all other records. The documentation states: ":offset - An integer determining the offset from where the rows should be fetched. So at 5, it would skip rows 0 through 4.".

In reality, you're required to specify a :limit as well. The way I got around this was by setting the limit to 'current_user.mymodels.count'.

I just wanted to point out that it's not documented that :limit is required for :offset to work. I actually had to go into the active record code to see why it wasn't working.

Reported by collink · March 10th, 2009 @ 05:28 AM

State: invalid
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Pratik
    Pratik
    • Assigned user set to Pratik
    • State changed from new to invalid

    This is not really an Active Record issue, but just the way SQL works.

    Thanks.

    March 10th, 2009 @ 11:57 AM

  2. collink
    collink

    I didn't say it was an active record issue...but, in my opinion, it's worth documenting that :limit is required for :offset to work. In the docs on api.rubyonrails.org, it fails to mention that :limit is required.

    March 10th, 2009 @ 02:43 PM