[Catalyst] paging with Data::Page

Ian Sillitoe ian at sillit.com
Mon Jul 27 20:32:36 GMT 2009


>
> Could be wrong, but I think the former is causing the resultset to be
> evaluated as an array and is therefore returning all the entries
> before the pager is being applied.
>

Apologies - I was talking rubbish about the usage of stash being the cause
(although I do think the resultset is being reset somewhere along the line).

Noting the following, I agree that the 'pager' code is probably correct
> and the 'result' code seems to be the gremlin. How they interact is
> beyond me


$result is a DBIx::Class::ResultSet object and is being returned from the
call to $c->model('Address::Addresses')->search(). This resultset object has
a method called $result->page($page_number) which sets up the database query
with the correct start and stop for the given page number and entries per
page (default=3D10). It also has a $result->pager() method which returns a
Data::Page object - this just provides a useful container for accessing
page-related information of the related DB query.


http://search.cpan.org/~ribasushi/DBIx-Class-0.08108/lib/DBIx/Class/ResultS=
et.pm

If the $pager is telling you the correct information (that the query only
has 10 entries) but this is changing by the time it is being rendered in
your template then perhaps another call is being made to the database (i.e.
because something else is changing $c->stash->result). Have you tried
setting DBIC_TRACE=3D1 in your environment and looking at the logs to check
that the database queries look sensible?

You could also check that the resultset at least has the correct number of
entries just before you leave your search function:

  $c->log->info( "Current Page: " . $page );
  $c->log->info( "Results: " . $result->count ); # NB: this will perform a
DB query
  $c->log->info( "Leaving 'search' method..." );

I note that Bindlex used to bring up a warning when the catalyst
> development server was started, but I do not see this now. Has Bindlex
> perhaps been un-deprecated?
>

Nope -
http://search.cpan.org/~mstrout/Catalyst-Controller-BindLex-0.05/lib/Cataly=
st/Controller/BindLex.pm


Cheers,

Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090727/d7dd6=
587/attachment.htm


More information about the Catalyst mailing list