Skip to content Skip to sidebar Skip to footer

Doctrine Query + Like Expression

I have problems to create a Doctrine Query with LIKE Expression: QUERY: $dql = 'SELECT u FROM Users u JOIN u.group g WHERE g.name LIKE lower('ADMIN')'; $query = $em->createQ

Solution 1:

The like string needs to have % signs. If you want something that starts with ADMIN then you would write ADMIN% if you want something that ends with ADMIN you would write %ADMIN and finally if you want it to contain ADMIN then it would be %ADMIN%.

Maybe to return a string you can use the CONCAT function of doctrine or you can do it via PHP.

Solution 2:

I tested this with QueryBuilder and there doesn't seem to be a solution. The second parameter will not take a function, so I would suggest switching the parameters around:

$dql    = "SELECT u FROM Users u JOIN u.group g WHERE UPPER(g.name) LIKE 'ADMIN'";

Post a Comment for "Doctrine Query + Like Expression"