[Dbix-class] Multiple joins, noob questions

Bill Moseley moseley at hank.org
Sun May 15 23:51:23 GMT 2011


On Sun, May 15, 2011 at 2:23 PM, Robert Kinyon <rob.kinyon at gmail.com> wrote:

> >
> > First, I make
> > my $user =3D $schema->resultset('User')->find(1);
> > Now I can get all user roles trought user object, but what can I do to
> > get this roles, ordered by role_rank?
>
> my @ordered_roles =3D map { $_->role } $user->user_roles( {}, { order_by
> =3D> 'role_rank' } );
>

role_rank is on the role (or roles, as the table is named), not the
user_role.

BTW  -- be careful doing things like that.  Probably minor in this case, but
might as well do that in a single query.  I tracked down a slow page the
other day and it turned out looping and and generating over a thousand
separate queries.  It's one of the reasons we must run database slaves.
 Avoid the looping.


-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20110515/b68=
e387e/attachment.htm


More information about the DBIx-Class mailing list