Hi fREW,
I would do something like: (not tested)
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_full = $self->schema()->resultset($table)->search($search,{
order_by => $self->query->param('sort')."
".$self->query->param('dir') || 'id',
columns => $columns
});
my $total = $rs_full->count;
my $rs = $rs_full->search({},{
rows => $self->query->param('limit') || 25,
});
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
my $data = { total => $total, data => []};
while (my $operation_code = $rs->next() ) {
push @{$data->{data}}, $operation_code;
}
return $self->json_body($data);
}
cheers,
J
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?
--
fREW Schmidt
http://blog.afoolishmanifesto.com
------------------------------------------------------------------------
_______________________________________________
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]
_______________________________________________
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]