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;
it will throw CDbCommand failed for use near ‘WHERE (owner_comp_id.id=t.owner_company_id)’ at line 1.
The SQL statement executed was: SELECT COUNT(DISTINCT t.id) FROM machinet LEFT OUTER JOIN companyowner_comp_id ON (t.owner_company_id=owner_comp_id.id) left join WHERE (owner_comp_id.id=t.owner_company_id).
join condition only can apply when using ON instead using WHERE. How to solve this problems? Anyone can help?
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.