offset not being applied to #first scope method #223

Closed
claco opened this Issue Jan 27, 2012 · 1 comment

Comments

Projects
None yet
2 participants

claco commented Jan 27, 2012

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

@mislav mislav closed this in 6d35492 Jan 10, 2013

Owner

mislav commented Jan 10, 2013

Good catch, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment