I am working on an Symfony 1.4 project and need to customize a backend filter "name", so that the column "name_full" is searched simultaneously with the "name" column.
I thought of doing it like that in my FormFilterClass:
public function addNameColumnQuery(Doctrine_Query $query, $field, $value) {
$rootAlias = $query->getRootAlias();
return $query->where(''.$rootAlias.'.name LIKE ?', "%$value%")
->orWhere(''.$rootAlias.'.name_full LIKE ?', "%$value%");
}
but that doesn't work as it gives me a wrong result set. And I fail to find the file where I could dump the complete dql for debugging.
Please point out where I could dump the complete dql or even tell me what is wrong with my approach.
Thank you!
EDIT: This is the correct function as suggested by Michal and tweaked by me:
public function addNameColumnQuery(Doctrine_Query $query, $field, $value)
{
$rootAlias = $query->getRootAlias();
return $query->addWhere(
''.$rootAlias.'.name LIKE ? OR '.$rootAlias.'.name_full LIKE ?',
array($value, $value)
);
}
Try changing this to:
By using
->where()
you overwrite the whole where part of the query so you could be deleting some conditions that were applied before the functionaddNameColumnQuery
was called. Also by using the above statement you will make sure that the two conditions joined withOR
will be in parenthesis, so you will havenot