1
votes

I've got an error that I don't understand with a doctrine query. I try to delete every entry with certain id with this :

$qb = $this->doctrine->em->createQueryBuilder();
                $query = $qb
                ->delete('route', 'r')
                ->where("r.user_id = 423")
                ->getQuery();

                $query->execute();

When I execute this one I've got this error :

Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'DELETE route r WHERE r.user_id = 423' in /var/www/mywebsite/application/libraries/Doctrine/ORM/Query/QueryException.php:39 Stack trace: #0 /var/www/mywebsite/application/libraries/Doctrine/ORM/Query/Parser.php(429): Doctrine\ORM\Query\QueryException::dqlError('DELETE route r ...') #1 /var/www/mywebsite/application/libraries/Doctrine/ORM/Query/Parser.php(854): Doctrine\ORM\Query\Parser->semanticalError('Class 'route' i...', Array) #2 /var/www/mywebsite/application/libraries/Doctrine/ORM/Query/Parser.php(1132): Doctrine\ORM\Query\Parser->AbstractSchemaName() #3 /var/www/mywebsite/application/libraries/Doctrine/ORM/Query/Parser.php(788): Doctrine\ORM\Query\Parser->DeleteClause() #4 /var/www/mywebsite/application/libraries/Doctrine/ORM/Query/Parser.php(734): Doctrine\ORM\Query\Parser->DeleteStatement() #5 /var/www/mywebsite/application/libraries/Doctrine/ORM/Query/Parser.php(229): Doctrine\ORM\Query\Parser->QueryLanguage() #6 /var/ in /var/www/mywebsite/application/libraries/Doctrine/ORM/Query/QueryException.php on line 49

I don't understand the meaning of this error. Thanks to anyone who can lead me to the right direction.

1

1 Answers

1
votes

This bit of the stack-trace seems to suggest that there is something worng with the classname.

...semanticalError('Class 'route' i...', Array) 

Are you sure you are correctly specifying the entity name? You should be using a fully qualified classname which includes the namespace.

Example: DELETE MyProject\Model\Route r WHERE r.user_id = 4

Solutions:

I. Just in case checks:

  1. Make sure the class name is correct. Both the case and namespace + classname.
  2. Run composer dump-autoload to make sure your classes are properly loaded.
  3. Make sure your entity exists and is properly mapped.

II. Use Doctrine's EntityManager remove method instead.

Example:

$em = new EntityManager();
$route= $em->find('route', 1);
$em->remove($route);
$em->flush();