i'm having some trouble deleting all records found by id using the query builder I tried like the bellow code but i'm always getting this error:
[Semantical Error] line 0, col 53 near 'b.id = :surv': Error: 'b' is not defined.
The Method:
public function deleteUsers($surveyId) {
$qb = $this->getEntityManager()->createQueryBuilder();
return $qb
->delete()
->from(BaseUser::class, 'a')
->leftJoin('a.survey', 'b')
->where('b.id = :survey')
->setParameter('survey', $surveyId)
->getQuery()
->execute()
;
}
You simply cannot use joins in a delete statement with Doctrine. One chance could be to get the ids which should be deleted of your joined results first and then do a simple 'delete where ids in'. This will work.
Please see this question/answer as well: Doctrine QueryBuilder delete with joins
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With