public function frontendProvider()
{
$query = new Query;
$query ->select('*')
->from('strategy')
->join('LEFT JOIN',
'risk_colors',
'risk_colors.id = risk_colors_id'
)
->join('LEFT JOIN',
'strategyoptions',
'strategyoptions.strategy_id = id'
);
$provider = new ArrayDataProvider([
'allModels' => $query->createCommand()->queryAll(),
'sort' => [
'defaultOrder' => [
'risk_colors_id' => SORT_DESC,
],
'attributes' => [
'strategy_title',
'strategy_description',
'strategy_current_money',
'color_number',
'risk_colors_id',
'options_value',
],
],
]);
return $provider;
}
我是新手,但似乎不确定我的表的这种关系,我不确定。我应该怎么做才能使事情正常?
答案 0 :(得分:1)
如果要联接两个具有相同列名(id
)的表,则需要在表名前加上列名,以指定应使用哪个表名:
$query ->select('*')
->from('strategy')
->join('LEFT JOIN',
'risk_colors',
'risk_colors.id = risk_colors_id'
)
->join('LEFT JOIN',
'strategyoptions',
'strategyoptions.strategy_id = strategy.id' // <- here
);