where子句中的Yii2列是不明确的

时间:2017-10-17 13:06:27

标签: php rest api yii2

导致错误的查询如下:

 $query = $model::find()
        ->leftJoin('reseller_config', 'reseller_rate.resellerref = reseller_config.resellerref')
        ->select('reseller_rate.*, reseller_config.resellerref AS rate_increase');

生成的sql如下:

SELECT COUNT(*) FROM `reseller_rate` LEFT JOIN `reseller_config` ON reseller_rate.resellerref = rc.resellerref WHERE `resellerref`=56

我知道它不起作用,因为这些字段的名称相同,并且不知道要抓哪个字段。

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

$query = $model::find()
    ->leftJoin('reseller_config', 'reseller_rate.resellerref = reseller_config.resellerref')
    ->select('reseller_rate.*', 'reseller_config.resellerref AS rate_increase');

你可以在查询bulider中使用它:

 $model = (new Query())
            ->select(['reseller_rate.*', 'reseller_config.resellerref AS rate_increase')
            ->from('reseller_rate')
            ->leftJoin('reseller_config', 'reseller_rate.resellerref = reseller_config.resellerref')
            ->all();