How to write the query in yii,using findAll()

后端 未结 3 1451
名媛妹妹
名媛妹妹 2021-01-28 23:27

I have the following sql query, how can I write the query in yii using findAll()?

I am not using CDbCriteria and for the time being avoiding i

3条回答
  •  时光取名叫无心
    2021-01-29 00:00

    $model = JobProfile::model()->with('userrelationname','categoryrelationname')->findAll(array("condition"=>"t.category_id =1 and t.experience =2 and t.key_skills LIKE '%php%'"));
    

    You can find relations names in your JobProfile model

    Example for relations

    There will be source code in your JobProfile Model File like

     public function relations(){
        return array(
          'user' => array (self::BELONGS_TO, 'User', 'id' ),
        )
     }
    

    Here is 'user' is relation name...

    then in your controller example;

    foreach($model as $m){
        echo $m['user_id']; // in your job_profile table
        echo $m->user->id;  // in your user table
    }
    

提交回复
热议问题