[Dbix-class] Running $rs->count() on full resultset?

Jesse Sheidlower jester at panix.com
Tue Apr 11 03:15:24 CEST 2006


On Mon, Apr 10, 2006 at 02:52:49PM +0100, Matt S Trout wrote:
> Jesse Sheidlower wrote:
> > I'm dynamically constructing my $rs search statements, and including
> > "page" and "rows" values in my attribute hash, for paged results.
> 
> Don't do it that way.
> 
> my $rs = $schema->resultset("CD")->search(...);
> 
> my $first_page_rs = $rs->page(1);
> 
> my $total_results = $rs->count;

I'm afraid this doesn't work.

  my $paged_rs = $full_rs->page($page); 

does, indeed, return a rs for the indicated page. But

  my $total_result_count = $full_rs->count;

continues to return the number of rows as given by the rows
attribute in the search statement. Needless to say it gives
this number regardless of how many rows are returned on a
given page (since the $total_result_count is derived without
reference to what page we're looking at).

Putting it another way, if my full search returns 230 records
and I'm looking at them 25 at a time, then $total_result_count
is 25, period. If my full search returns fewer than the number
given by "rows", I do get the correct number from count().

Jesse Sheidlower



More information about the Dbix-class mailing list