Multiple Joins With Alias


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('' => array('alias' => 'c1')));

$mod->with(array('' => 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?


    '' => array('alias' => 'c1'),

    '' => array('alias' => 'c2'),



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

OK i found:


    '' => array('alias' => 'c1'),

    '' => array('alias' => 'c2'),

    '' => array('alias' => 'cc1'),

    '' => array('alias' => 'cc2'),


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


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

'' => array('alias' => 'c2'),

is there a other way to do this ?


you can use CDbCriteria

for example…

            $criteria = new CDbCriteria;

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

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

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

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

            return $resultSet;