Aiuto sql con Query Builder

ciao ragazzi

ho una query sql che non riesco a farla trasformare in query builder


SQL= "SELECT r.id as id, r.date as date, r.title as title,r.description as description, s.description as source_id, r.inserted_on as inserted_on

      FROM researches r

      LEFT JOIN sources s ON s.id=r.source_id

      WHERE s.id=".$model->source_id." OR r.title LIKE '".%$model->title%."' OR r.tag LIKE '".$tag1."' OR  r.tag LIKE '".$tag2."';





$rs = Yii::app()->db->createCommand()->select('r.id as id, r.date as date, r.title as title,r.description as description, s.description as source_id, r.inserted_on as inserted_on')

				     ->from('researches r')

				     ->leftJoin('sources s', 's.id=r.source_id')

				     ->where("")

				     ->queryAll();

Sono riuscito a fare tutto tranne la where che non ho idea di come fare.

In che senso non sei riuscito? Con che input hai provato e che errore ti ha dato?

Potrebbe andare qualcosa del genere:


->where(

    "s.id = :source_id  OR r.title LIKE '%:title%' OR r.tag LIKE ':tag1' OR  r.tag LIKE ':tag2'"

    ,

    array(

        ':source_id' => $model->source_id,

        ':title' => $model->title,

        ':tag1' => $tag1,

        ':tag2' => $tag2,

    )

)

Okay adesso mi funziona.

Anche prima avevo provato a fare una cosa del genere, però mi dava errore invece questa volta è andato a buon fine.

Grazie mille