Activerecord multiple conditions with LIKE

Hi there!

I am running into problems with multiple conditions in ActiveRecord sql querying.

I have a form which is using checkboxlist and I am using it to list out matching records.

My form works correctly so I am not going to post those.

However, the above query code can only do exact sql matches, even though it is successfully running with the ‘lesson_type’ => [‘LIKE’, ‘lesson_type’, $searchitems->lesson_type] conditions.

Using solely [‘LIKE’,lesson_type, $searchitems->lesson_type] works, but it is only one query condition.

How can I solve this? Thank you!

EDIT: solved it! For future reference, working code:

$query = Model::find()->where([‘role’ => ‘teacher’])->andWhere([‘LIKE’, ‘lesson_type’, $searchitems->lesson_type]);

1 Like