Multiple Joins With Alias

Hello

I have a problem with my models and activerecord

i need to join one table more than once, so im using alias like this


$mod->with(array('route.country' => array('alias' => 'c1')));

$mod->with(array('route.country' => array('alias' => 'c2')));

the problem is that table country relates to table city, which i need to join too - to the both aliased tables (c1 and c2)

and i cant move forward atm

is there a way to do this insteed to write regular sql query?

thanks in advance

Hi jandon, welcome to the forum.

Would you please try this?




$mod->with(array(

    'route.country' => array('alias' => 'c1'),

    'route.country' => array('alias' => 'c2'),

));



Thanks

Yeah it works, but how to make a join on a aliased table?

OK i found:




$mod->with(array(

    'route.country' => array('alias' => 'c1'),

    'route.country' => array('alias' => 'c2'),

    'route.country.city' => array('alias' => 'cc1'),

    'route.country.city' => array('alias' => 'cc2'),

));



Yah i did it finally, don’t know why that seemd to be impossible hour ago.

Thanks

ok i need to make a little bump here

because what i’ve just found - that solution doesn’t work well.

array key is equal method receive only last row, which in my case is


'route.country' => array('alias' => 'c2'),



is there a other way to do this ?

Hi,

you can use CDbCriteria

for example…


            $criteria = new CDbCriteria;

            $criteria->select = 't.*, tu.* ';

            $criteria->join = ' LEFT JOIN `user_crew` AS `tu` ON t.id = tu.user_id';

            $criteria->addCondition("display_name LIKE '%a%' and blocked_by='76'");

            $resultSet    =    Customer::model()->findAll($criteria);

            return $resultSet;