"Semantical Error" line 0, col 14 near 'User u WHERE': Error: Class 'User' is not defined2020-05-27 doctrine-orm
I have a Symfony 5 project which has default authentication and
User entity. I was reading Doctrine documentation in order to use
$em->createQueryBuilder() function but I got this error:
[Semantical Error] line 0, col 14 near 'User u WHERE': Error: Class 'User' is not defined.
I just need to query some users with an specific role so I wrote the following code in the controller:
$em = $this->getDoctrine()->getManager(); $qb = $em->createQueryBuilder(); $category_users = $qb->select(array('u')) ->from('User', 'u') ->where('u.category = ' . $category->getId()) ->setParameter('roles', '%"ROLE_CUSTOM"%') ->orderBy('u.name', 'ASC') ->getQuery() ->getResult();
I know the error does not have to do with writing the query itself and I guess this could have two questions, but just in case...
Question 1: What am I forgetting to get this error? I have read in previous versions of Symfony I should add Bundle name to
from('User', 'u') but I am not sure about this version.
Question 2: Is this code optimal for this kind of query? Or maybe I am overcomplicating stuff?
You must use a FqCN for the Entity.
- Doctrine- Group by date
- Doctrine2, Symfony2. Oracle Error:Class has no field or association named user_id
- Doctrine "has no association named"
- Symfony2 Semantical Error
- Group By day and month Doctrine
- Doctrine: ordering By Count on Associated entities
- Symfony2 Doctrine Custom Repository Class [Semantical Error] line 0, col 14 near 'Project p': Error: Class 'Project' is not defined
- How to use user defined variables with MySQL?