From: Matt S Trout Date: Tue, 17 Jul 2007 23:07:06 +0000 (+0000) Subject: fix for count after slice (report and tests from JOHANL) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2bd9c7c03aed580188fa1a4b9554ec5ce475dcea;p=dbsrgits%2FDBIx-Class-Historic.git fix for count after slice (report and tests from JOHANL) --- diff --git a/Changes b/Changes index da22d82..3d7ef2d 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx::Class + - count no longer returns negative values after slice + (report and test from JOHANL) - rebless before building datetime_parser (patch from mattlaw / Matt Lawrence) diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 8d9f569..75ba410 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -938,6 +938,7 @@ sub count { $count -= $self->{_attrs}{offset} if $self->{_attrs}{offset}; $count = $self->{attrs}{rows} if $self->{attrs}{rows} and $self->{attrs}{rows} < $count; + $count = 0 if ($count < 0); return $count; } diff --git a/t/76joins.t b/t/76joins.t index a401927..92e5785 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -16,7 +16,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 63 ); + : ( tests => 64 ); } # figure out if we've got a version of sqlite that is older than 3.2.6, in @@ -146,6 +146,9 @@ $rs = $schema->resultset("CD")->search( ); cmp_ok( scalar $rs->all, '==', scalar $rs->slice(0, $rs->count - 1), 'slice() with join has same count as all()' ); +ok(!$rs->slice($rs->count+1000, $rs->count+1002)->count, + 'Slicing beyond end of rs returns a zero count'); + $rs = $schema->resultset("Artist")->search( { 'liner_notes.notes' => 'Kill Yourself!' }, { join => { 'cds' => 'liner_notes' } });