Subject: | DBIx::Class Bug: Offset Always Incremented |
Date: | Thu, 7 Jun 2007 11:57:04 -0700 |
To: | bug-DBIx-Class [...] rt.cpan.org |
From: | "John Seaver" <john.seaver [...] gmail.com> |
Whenever a ResultSet is "cloned" the offset is incremented instead of simply
re-calculated.
Here is how to re-create the problem:
for (1 .. 10) {
$rs = $rs->search({}, { page => 2, rows => 25 });
print $rs->{'attrs'}->{'offset'}, "\n";
}
Or using a more direct method...
for (1 .. 10) {
$rs = $rs->page(2);
print $rs->{'attrs'}->{'offset'}, "\n";
}
Here is a patch to fix the problem:
--- ResultSet.pm.orig Thu Jun 7 11:46:21 2007
+++ ResultSet.pm Thu Jun 7 11:46:37 2007
@@ -91,7 +91,7 @@
if ($attrs->{page}) {
$attrs->{rows} ||= 10;
$attrs->{offset} ||= 0;
- $attrs->{offset} += ($attrs->{rows} * ($attrs->{page} - 1));
+ $attrs->{offset} = ($attrs->{rows} * ($attrs->{page} - 1));
}
$attrs->{alias} ||= 'me';