http://www.perlmonks.org?node_id=769710


in reply to Re: Problems with DBIx::Class and SQL JOIN's
in thread Problems with DBIx::Class and SQL JOIN's

Two observations:

It works... as long as you only search by one role at a time. I don't know why, but I'll take what I can get! You have my gratitude.

It does not work if you remove the plus ("+") sign from the "+select", and "+as" hash keys. Why is this so?

Could anyone shed some light on why this works? If I know why/how it works, then I'll never have to ask related questions again --I'll already know the underlying principle and be able to apply it.

Again, my thanks to you, Arunbear!

--
Tommy
  • Comment on Re^2: Problems with DBIx::Class and SQL JOIN's

Replies are listed 'Best First'.
Re^3: Problems with DBIx::Class and SQL JOIN's
by Arunbear (Prior) on Jun 09, 2009 at 16:38 UTC
    You only get one role at a time because the search was limited to the 'friend' role. To change that you need to change the 'where' criteria in the 1st hashref:
    $c->model('DB::Users')->search_like( { 'username' => '%foo%' }, { join => { 'map_user_role' => 'role' }, '+select' => [ 'role.id', 'role.role' ], '+as' => [ 'roleid', 'role' ], rows => 10, }, );
    The plus ("+") sign is needed because 'role.id' and 'role.role' do not originate in the Users schema/table