我已經成功地通過實施http://www.yiiframework.com/wiki/653/displaying-sorting-and-filtering-model-relations-on-a-gridview/。哪裏工作得很好,我的關係名字只是一個單詞。但是,我的關係名稱是subSector
,我得到:Column not found: 1054 Unknown column 'subSector.sub_sector' in 'where clause'
。Yii2關於相關模型中關係名稱較低的過濾器camelCase
public function search($params)
{
$query = Product::find();
// add in relation to be able to search with
$query->joinWith(['sector', 'subSector'];
...
$dataProvider->sort->attributes['sub_sector_search'] = [
// The tables are the ones our relation are configured to
'asc' => ['subSector.sub_sector' => SORT_ASC],
'desc' => ['subSector.sub_sector' => SORT_DESC],
];
...
$query->andFilterWhere([
'product_id' => $this->product_id,
...
])
->andFilterWhere(['like', 'subSector.sub_sector', $this->sub_sector_search])
我還在類初始化下面添加了參數,並在規則中添加了安全術語。
到目前爲止,所有3個單個單詞關係都適用於過濾,並且兩個模型關係都是camelCase返回unknown column
。
什麼是你的'subSector'關係TableName –