0

I'm trying to filter a yii2 gridview with a select2

In ModelSearch I have

 ->andFilterWhere(['like', 't_persons.functions', $this->functions ])

Unfortunately string (1) matches 10 and 11 as well

enter image description here

How can I filter the integer values from the comma separated field?

user 1007017
  • 391
  • 2
  • 10

2 Answers2

0

If you have a string of comma separated values, I would try:

->andFilterWhere('t_persons.functions in ('.$this->functions.')')
gmc
  • 3,910
  • 2
  • 31
  • 44
0

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();
Rich Harding
  • 645
  • 6
  • 14