Hi There,
I had a search builder working fine when i was searching for records.
My code was like this:
$query->orWhere([‘LIKE’, ‘username’, ‘searchvalue’]);
$query->orWhere([‘LIKE’, ‘customername’, ‘searchvalue’]);
$query->orWhere([‘LIKE’, ‘email’, ‘searchvalue’]);
But now I have needed to add a hard filter.
$query->andWhere([’=’, ‘company_id’ 5]);
The problem i get now when trying to search company 5’s records is it is generating a query similar to
SELECT * FROM table WHERE company_id = 5 OR username LIKE ‘%searchvalue%’ OR customername LIKE ‘%searchvalue%’ OR email LIKE ‘%searchvalue%’
But what I am after is putting those OR’s in brackets so i get something like this:
SELECT * FROM table WHERE company_id = 5 AND ( username LIKE ‘%searchvalue%’ OR customername LIKE ‘%searchvalue%’ OR email LIKE ‘%searchvalue%’)
I have been staring at this page for ages: http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html trying all sorts of things out. But cant seem to get the query builder to do exactly what I need.
Any help would be appreciated.