[Catalyst] DBIx::Class/TT Pager Question
Dennis Daupert
ddaupert at sbcglobal.net
Fri Dec 29 21:37:39 GMT 2006
Leandro:
> you don't need to use Data::Page directly
yes, you are quite right, I took out the
explicit call to Data::Page; I set rows => 2,
and my query gets 2 thumbs. Cool.
>you are setting $c->stash->{photos} to an
>array reference when you do
>$c->stash->{photos} = [$c->model( ... ];
>and then you are later trying to make a
>method call ->pager() on that array reference,
>not an object.
With the square brackets, I get an array ref,
and in my template, I do stuff like:
[% FOREACH photo IN photos -%]
[% photo.gallery.name %]
[% END -%]
When I take the square brackets out of the
query, my template doesn't display anything
anymore.
>See the "Paged Results" section of the
>DBIx::Class::Manual::Cookbook POD on
>CPAN.
which of course I'd been trying to beat
into my forehead. Cookbook says:
"you can return a Data::Page object for the resultset
(suitable for use in e.g. a template)
using the pager method:
return $rs->pager();"
So I'm trying to call the pager method from the
resultset. But translating from the cookbook
example (which is non-Catalyst centric) to
Cat code, falls the shadow.
Chisel:
>$c->stash->{pager} => $c->stash->{photos}->pager();
>shouldn't this be an assignment rather than a fat-comma?
Good eyeballs! Yes.
>I think you need to lose the square brackets,
>and you will probably find you then have a
>DBIx::Class::ResultSet, which does have the
>pager() method.
When I do, I get this error:
Caught exception in Catapult::Controller::Photo::Gallery->display "DBIx::Class::ResultSet::pager(): Can't create pager for non-paged rs
Going back to the DBIx::Class Cookbook example,
which is pretty simple (no joins or anything), do I
have the joins and the row settings in the right place?
I tried a few combos, and the one that at least doesn't
throw cat down the stairs is the one I have been using:
$c->stash->{photos} = [$c->model('CatapultDB::Photos')->search(
{
'gallery.id' => $selected_gallery
},
{
join => [qw/ gallery /],
prefetch => [qw/ gallery /],
rows => 2,
}
)];
Much less hair now,
/dennis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061229/462444ce/attachment.htm
More information about the Catalyst
mailing list