Thyu
Thyu

Reputation: 109

How to add join query into yii search function

What I wanna know is, how to add join query into yii search function.

Search function is in the currency model.(currency.php)

>public function search()
    {

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id,true);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('sign',$this->sign,true);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }

I wanna add the join query to that function. Myquery is like that:

SELECT * FROM currency cur INNER JOIN currency_option curopt ON cur.id = curopt.currency_id AND curopt.company_id = '$com_id'.

Anyone please help me. Thanks a lot!

Upvotes: 0

Views: 1190

Answers (1)

n3ISe
n3ISe

Reputation: 159

$criteria=new CDbCriteria;
$criteria->join="INNER JOIN currency_option curopt ON cur.id = curopt.currency_id AND curopt.company_id = '$com_id'";
$criteria->compare('id',$this->id,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('sign',$this->sign,true);

Try this.

Upvotes: 2

Related Questions