CDbCriteria:: with

Hi guys,

how to use left join function to compare field inside public function search?? How to set left join condition even company record is null value?

 public function relations()


   'owner_comp_id' => array(self::BELONGS_TO, 'company', 'owner_company_id'),  //,'joinType'=>'LEFT OUTER JOIN'


 public function search()


        // Warning: Please modify the following code to remove attributes that

        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('user_name', $this->user_name, true);

        $criteria->compare('owner_comp_id.company_name', $this->company_name, true);

        $criteria->with = array('owner_comp_id');

        $criteria->together = true;

$criteria->with = array('owner_comp_id'=>array('join'=>'left join','condition'=>'blabla'));

Hi Khoe Le,

$criteria->with = array('owner_comp_id'=>array('join'=>'left join','condition'=>'blabla'));

it will throw CDbCommand failed for use near ‘WHERE (’ at line 1.

The SQL statement executed was: SELECT COUNT(DISTINCT FROM machine t LEFT OUTER JOIN company owner_comp_id ON ( left join WHERE (

join condition only can apply when using ON instead using WHERE. How to solve this problems? Anyone can help?

Can you change ‘join’ to ‘joinType’?

Hi Khoe Le,

Sorry for late reply,

The error is different now. It shows "Trying to get property of non-object" when the owner_company_id is null value. The error wont happen when the owner_company_id got value or record.

How to solve this problem? Thx.