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

will at serensoft.com will at serensoft.com
Sat Jun 12 19:43:58 GMT 2010


Ah, after adding "join =3D> 'team'" (and tweaking fields to distinguish me.*
items) that did the trick, thanks!

    $team_ids =3D [
        map { "me.team" =3D> $_ } @id_list
    ];
    my $users =3D $c->model('My::User')
        ->search_rs( $team_ids, {
            join     =3D> 'team',
            order_by =3D> [ qw/team.name me.lastname me.firstname/ ],
        } );

Excellent, thanks!


On Sat, Jun 12, 2010 at 2:11 PM, Octavian Rasnita <orasnita at gmail.com>wrote:

> You can use an order_by block like:
>
> order_by =3D> [
> {-asc =3D> 'team.name'},
> {-asc =3D> 'me.lastname'},
> {-asc =3D> 'me.firstname'},
> ],
>
> Or, if there is -asc for everyone, you can use:
>
> order_by =3D> ['team.name', 'me.firstname', 'me.lastname'],
>
> In the order_by blocks you need to use the names of the columns as they a=
re
> used in the generated SQL query. For finding those names, use
> $ENV{DBIC_TRACE}++.
>
> HTH.
>
> Octavian
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>



-- =

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/5f4a0=
a37/attachment.htm


More information about the Catalyst mailing list