I am using EntityReference Autocomplete with filter by entity reference view. And I want to ignore space in search filed.
For example, column username
in DB has value first name
it should popup when user types first
or firstname
. To achieve this I wrote hook_views_query_alter
to change the condition, I would like to pass the condition as REPLACE(username, ' ', '') LIKE '%firstname%'
.
Even if I set field value in condition to REPLACE(username, ' ', '')
its getting changed to REPLACEusername
. Even I tried running the query separately, like below in node,
$query = db_select('node', 'n')
->fields('n', array('title'))
->condition('type', 'article', '=')
->condition('REPLACE(n.title, \' \', \'\')', $category, 'LIKE')
When I output query prints like below,
SELECT n.title AS title FROM {node} n WHERE (type = 'article') AND (REPLACEn.title LIKE '%articleone%' ESCAPE '\\')
How can I set it correctly? Is there any other way to do?