You could get around this by passing :limit => MyModel.count option to the finder but this adds the unnecessary overhead of an additional query. Instead I prefer to pass a value that is more than the largest possible value for the primary key, like this:
MyModel.all :offset => 100, :limit => 2**32, :order => :name
In this example MyModel has a regular integer sized primary key so 2**32 is larger than the maximum number of records that can be stored in the table, so we’re guaranteed to get all the records from offset 100 onwards.


2 comments
Comment on Giving ActiveRecord finders an :offset but not a :limit by Tom Ward
April 9th, 2009 @ 08:21 – permalink
Comment on Giving ActiveRecord finders an :offset but not a :limit by Rob Anderton
April 9th, 2009 @ 08:54 – permalink
Leave a reply
You can use Markdown in your comment as well as plain HTML. You can use
<filter:jscode lang="ruby">and</filter:jscode>tags to surround code blocks (supported languages are css, html, javascript and ruby). Your email address will not be published.If your comment doesn’t appear immediately after posting it could have been marked as spam. Don’t worry: we regularly check for and approve incorrectly filtered comments so you shouldn’t have to wait too long for it to be shown.