我已经成功地通过实施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 –