On Mon, May 16, 2011 at 11:45, Oleg Kostyuk <cub.ua...@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

_______________________________________________
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/dbix-class@lists.scsys.co.uk

Reply via email to