P
P
Pepper12021-11-03 08:52:57
Yii
Pepper1, 2021-11-03 08:52:57

YII2 model GRIDVIEW SEARCH search for an exact match in a string separated by commas, how to do?

Hello.

In my site on YII2, article categories (one article can have many of them) are stored in the database in a row (it can be 12 or 12, 19, 145).

Whoever says that it's wrong to store it this way - I agree, but it's too late to remake the database is already full of more than 1000 rows of the article table, not counting other related ones.

The category selection uses GRIDVIEW and the SEARCH model: ->andFilterWhere(['like', 'cat', $this->cat]) and, accordingly, when choosing 1, it will be shown where there is 1, that is, 1 and 12, 19, 145. But it is necessary that there is a strict match, and without LIKE how to search the string in this way, I don’t know how ... So that when choosing 1, only one would be shown, and not everywhere where there is 1 ...

Maybe someone has any thoughts? Can you share how to fix this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2021-11-03
@Pepper1

In your case https://oracleplsql.ru/mysql-function-find_in_set.html MySql (5.7) -
FIND_IN_SET( string, string_list )
But if you don't change the structure too much, I would rewrite the column to Json, it's more pleasant to work with.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question