I'm trying to do a query for bulk deleting, but apparently it doesn't do the JOIN actions. Any thoughts?
$queryBuilder = $em
->createQueryBuilder()
->delete('Bundle:ClassA', 'a')
->join('a.classB', 'b')
->where('b = :parent')
->setParameter('parent', $parent);
$queryBuilder->getQuery()->execute();
This returns:
"[Semantical Error] line 0, col 38 near 'b = :parent AND': Error: 'b' is not defined."
DQL does not support joins in DELETE and UPDATEs, even if the underlaying database, like MySQL, supports it.
This is the quickiest workaround:
$results = $em
->createQueryBuilder()
->select('Bundle:ClassA', 'a')
->join('a.classB', 'b')
->where('b = :parent')
->setParameter('parent', $parent)
->getQuery()->getResult();
foreach ($results as $result){
$em->remove($result);
}
$em->flush();
try this :
$queryBuilder = $em
->createQueryBuilder()
->delete('Bundle:ClassA', 'a')
->innerJoin('a.classB', 'b')
->where($qb->expr()->eq('b', ':parent'))
->setParameter(':parent', $parent);
$queryBuilder->getQuery()->execute();
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