You could solve this easily by using the 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 you replace getQuery
with getDQL
you can see how this translates into DQL (or getSQL
)
What essentially is wrong in your method is the from
in your Delete statement as delete in DQL looks like this:
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'DELETE StreetBumbApiBundle:BussOwner buss
WHERE buss.id = :bussId')
->setParameter("bussId", $bussId);
$query->execute();
Also, I am not sure why you use $query->getResult()
.
What would be the expected result of a delete? $query->execute();
does the job.
Apart from that, if you don't do complex delete statements, and in your case you are deleting an Entity querying with an Id.
Why not:
$em = $this->getDoctrine()->getManager();
$em->remove($entity);
And therefore pass the Entity, not just the Id to your delete function?
"An exception occurred while executing 'DELETE FROM BussOwner WHERE id = ?' with params [\"2\"]:\n\nSQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (
withinseventytwo.
offerList, CONSTRAINT
FK_85A42F448195E83B` FOREIGN KEY (bussId
) REFERENCESBussOwner
(id
))"` – Pituri