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

I think your search should look something like:
$c->model('DB::Users')->search( { 'role.role' => 'friend' }, { join => { 'map_user_role' => 'role' }, '+select' => [ 'role.id', 'role.role' ], '+as' => [ 'roleid', 'role' ], rows => 10, }, );

Replies are listed 'Best First'.
Re^2: Problems with DBIx::Class and SQL JOIN's
by Tommy (Chaplain) on Jun 08, 2009 at 22:43 UTC
    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
      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