From: Rafael Kitover Date: Wed, 17 Jun 2009 17:50:47 +0000 (+0000) Subject: fix page with offset bug X-Git-Tag: v0.08108~82 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5b1c7d7ff82168fb219aa09be6902695f2cd5af8;p=dbsrgits%2FDBIx-Class.git fix page with offset bug --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index ed2d144..4038fb6 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2622,8 +2622,10 @@ sub _resolved_attrs { $attrs->{collapse} = $collapse; - if ( $attrs->{page} and not defined $attrs->{offset} ) { - $attrs->{offset} = ( $attrs->{rows} * ( $attrs->{page} - 1 ) ); + if ($attrs->{page} && not exists $attrs->{resolved_offset}) { + $attrs->{offset} = ($attrs->{rows} * ($attrs->{page} - 1)) + + ($attrs->{offset} || 0); + $attrs->{resolved_offset} = $attrs->{offset}; } return $self->{_attrs} = $attrs; diff --git a/t/67pager.t b/t/67pager.t index 17b05c3..6a6aabc 100644 --- a/t/67pager.t +++ b/t/67pager.t @@ -84,3 +84,19 @@ is($p->(), 10, 'default rows is 10'); $schema->default_resultset_attributes({ rows => 5 }); is($p->(), 5, 'default rows is 5'); + +# test page with offset +$it = $schema->resultset('CD')->search({}, { + rows => 2, + page => 2, + offset => 1, + order_by => 'cdid' +}); + +my $row = $schema->resultset('CD')->search({}, { + order_by => 'cdid', + offset => 3, + rows => 1 +})->single; + +is($row->cdid, $it->first->cdid, 'page with offset');