[Dbix-class] Pagination Troubles
Jess Robinson
castaway at desert-island.me.uk
Wed Mar 11 08:06:11 GMT 2009
On Thu, 5 Feb 2009, fREW Schmidt wrote:
> Hi all!
>
> I am trying to paginate some results and I need to get the count of the full
> results. I tried to use count and that only gives the amount that are in
> the current result set. I tried to do this:
> http://lists.scsys.co.uk/pipermail/dbix-class/2006-April/001204.html But
> got errors about trying to call pager on non-paged data. Here is my code:
>
> sub basic_data {
>> my $self = shift;
>> my $params = shift;
>>
>> my $table = $params->{table};
>> my $search = $params->{search};
>> my $columns = $params->{columns};
>>
>> use DBIx::Class::ResultClass::HashRefInflator;
>>
>> my $rs = $self->schema()->resultset($table)->search($search,{
>> rows => $self->query->param('limit') || 25,
>> order_by => $self->query->param('sort')."
>> ".$self->query->param('dir') || 'id',
>> columns => $columns
>> });
>>
>> $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
>>
>> my $data = { data => []};
>>
>> while (my $operation_code = $rs->next() ) {
>> push @{$data->{data}}, $operation_code;
>> }
>> $data->{total} = $rs->count;
>>
>> return $self->json_body($data);
>> }
>>
>
> Can anyone tell me what I should be doing?
We have "pager" for this, i.e.:
$rs->pager->total_enries, will give you all entries without paging.
See ResultSet docs.
Jess
More information about the DBIx-Class
mailing list