[Catalyst] HOWTO: order_by a field in a related record, for paging

will at serensoft.com will at serensoft.com
Sat Jun 12 14:22:30 GMT 2010

$c->model()->search( {}, {order_by=3D>???, page=3D>$page} )

How do we "order_by" a field from a related record when pulling a resultset?
We want to order users by team (then by lastname, firstname) and be able to
PAGE back and forth...

e.g. a User belongs_to a Team.

    my $team_name  =3D $c->user->team->name;

    my $users =3D $c->model('My::User')
        ->search_rs( {}, {
            order_by =3D> {
                -asc =3D> ???user->team->name???,  ###### howto?
                -asc =3D> 'lastname',
                -asc =3D> 'firstname',
            page =3D> $page,
        } );

We're wanting to order by team-name, then user-lastname, then

Here's a perl sort AFTER we have the results:

    my $user_collection =3D [
        sort {
                $a->team->name cmp $b->team->name ||
                $a->lastname   cmp $b->lastname   ||
                $a->firstname  cmp $b->firstname

But this approach doesn't allow for paging backward and forward over the

-- =

will trillich
"I think it would be worse to expect nothing than to be disappointed." --
Anne (with an 'e') Shirley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100612/91ad2=

More information about the Catalyst mailing list