symfony - DELETE query not working in DQL doctrine Symfony2 -


i delete row based on id, , used query task:

 $em = $this->getdoctrine()->getmanager();     $query = $em->createquery('delete buss streetbumbapibundle:bussowner buss buss.id = :bussid')         ->setparameter("bussid", $bussid);     $list = $query->getresult(); 

but getting error:

{ "code": 500, "message": "[semantical error] line 0, col 7 near 'buss streetbumbapibundle:bussowner': error: class 'buss' not defined." }

what wrong doing?

you solve using querybuilder:

$em = $this->getdoctrine()->getmanager(); $qb = $em->createquerybuilder(); $query = $qb->delete('streetbumbapibundle:bussowner', 'buss')             ->where('buss.id = :bussid')             ->setparameter('bussid', "bussid")             ->getquery();  $query->execute(); 

btw: if replace getquery getdql can see how translates dql (or getsql)

what wrong in method from in delete statement delete in dql looks this:

$em = $this->getdoctrine()->getmanager(); $query = $em->createquery(               'delete streetbumbapibundle:bussowner buss                 buss.id = :bussid')             ->setparameter("bussid", $bussid);  $query->execute(); 

also, not sure why use $query->getresult(). expected result of delete? $query->execute(); job.

apart that, if don't complex delete statements, , in case deleting entity querying id.

why not:

$em = $this->getdoctrine()->getmanager(); $em->remove($entity); 

and therefore pass entity, not id delete function?


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -