On Sun, May 15, 2011 at 11:26, Александер Пономарёв <[email protected]> wrote:
> An additional question:
> how can I use such oerations like order by in joined table?
> For example, almost the same tables
> user {
>    id_user,
>    user_name
> }
> roles {
>    id_role,
>    role_name,
>    role_rank
> }
> user_roles {
>    id_user,
>    id_role
> }
>
> First, I make
> my $user = $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 = map { $_->role } $user->user_roles( {}, { order_by
=> 'role_rank' } );

The key is that the accessor for a has-many relationship returns a
resultset. In list context, that returns the rows in the resultset. In
scalar context, it returns the resultset. As a result, you can pass in
all the arguments to ->search() because that's what is being called
under the covers.

Rob

_______________________________________________
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]

Reply via email to