Yii 2.0 Left Join Search Code Demo

{ Table }

 

Client[c_id, c_name]

Order[o_id, o_client_id, o_amount]

 

{ Code }

// models/xxxxSearch.php

// Correct Demo
$staffs = Client::find();

// left join and search

$staffs->leftJoin('order', 'c_id = o_client_id');

$staffs->andWhere(['c_role_id'=>5]);

 

 

// InCorrect

$staffs->leftJoin('order', ['c_id' => 'o_client_id']);