mislav/will_paginate — Issue #223: offset not being applied to #first scope method
Author: claco
Created: 2012-01-27 18:20:42+00:00
State: open

rails 3.1 / 3.2 + will_paginate 3.0.2

After calling #paginate to get a scope in AR, calling #first yields sql that doesn't correctly apply OFFSET. Calling #all and #last yields the expected results. Doing the same in AR w/o #paginate works as expected.

Person.paginate(:per_page => 20, :page => 2).all
SELECT "people".* FROM "people" LIMIT 20 OFFSET 20

Person.paginate(:per_page => 20, :page => 2).last
SELECT "people".* FROM "people" LIMIT 20 OFFSET 20

Person.paginate(:per_page => 20, :page => 2).first
SELECT "people".* FROM "people" LIMIT 1 OFFSET 1 <-- This should be OFFSET 20 to get the first record of page 2

Using AR scopes:

Person.limit(20).offset(20).all
SELECT "people".* FROM "people" LIMIT 20 OFFSET 20

Person.limit(20).offset(20).last
SELECT "people".* FROM "people" LIMIT 20 OFFSET 20

Person.limit(20).offset(20).first
SELECT "people".* FROM "people" LIMIT 1 OFFSET 20

Person.limit(1).offset(20).first
SELECT "people".* FROM "people" LIMIT 1 OFFSET 20