2017-07-03 10:14:19 0 评论 Yii 2.0 Boy.Lee

Yii 2.0 Left Join 搜索代码示例

{ Table }

 

Client[c_id, c_name]

Order[o_id, o_client_id, o_amount]

 

{ Code }

// models/xxxxSearch.php

// 正确代码
$staffs = Client::find();

// left join and search

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

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

 

 

// 错误代码

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