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


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to