[Dbix-class] Multiple joins, noob questions

Oleg Kostyuk cub.uanic at gmail.com
Mon May 16 19:44:46 GMT 2011


2011/5/16 Robert Kinyon <rob.kinyon at gmail.com>:
> 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.

What about to personally me - then yes, you are correct: in most cases
I will want result set or object. But I'm not topic starter - and in
this particular topic he asked about ordered list of values from one
column. I just answered to question exactly :)

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



-- 
Sincerely yours,
Oleg Kostyuk (CUB-UANIC)



More information about the DBIx-Class mailing list