导致错误的查询如下:
$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
我知道它不起作用,因为这些字段的名称相同,并且不知道要抓哪个字段。
有谁知道如何解决这个问题?
答案 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();