我正在尝试使用 select2 过滤 yii2 gridview
在 ModelSearch 我有
->andFilterWhere(['like', 't_persons.functions', $this->functions ])
不幸的是,字符串 (1) 也匹配 10 和 11
如何过滤逗号分隔字段中的整数值?
To match a single value in a comma-separated field use FIND_IN_SET, e.g.:
SELECT * FROM t_persons WHERE FIND_IN_SET('3', functions);
To integrate that into Yii2, you might (if I've understood your nomenclature correctly) use:
->andFilterWhere(new Expression('FIND_IN_SET(:function_to_find, functions)'))->addParams([':function_to_find' => $this->functions])->asArray()->all();
如果您有一串逗号分隔值,我会尝试:
->andFilterWhere('t_persons.functions in ('.$this->functions.')')