[Dbix-class] Multiple joins, noob questions

Robert Kinyon rob.kinyon at gmail.com
Mon May 16 16:14:12 GMT 2011


On Mon, May 16, 2011 at 11:45, Oleg Kostyuk <cub.uanic at gmail.com> wrote:
>> my @ordered_roles =
>> $user->search_related('user_roles')->search_related( 'roles', {}, {
>> order_by => 'role_rank' } );
[snip]
> Where is difference from this? There will be only one query too:
>
> my @ordered_roles =
> $user->search_related('user_roles')->search_related('roles', undef,
> {order_by => 'role_rank' })->get_column('role')->all;
>
> By the way, this will fetch only needed column, instead of all, and so
> should be faster. This can be important - if this query will be
> repeated often, of course.

You almost never want just the column. You want the result object.
Your way only gets the value in the column called 'role' on the roles
table. Mine gets the Role result object. Still only one query.

As for faster, the difference is going to be in micro-seconds. And,
it's almost guaranteed that you will piss away all the savings in lost
programmer productivity.

Rob



More information about the DBIx-Class mailing list