Will you give me an example of a delete query that use a left join using Doctrine?
It's not possible. See that: http://trac.doctrine-project.org/ticket/2142
You have to use a subquery in the where clause: http://www.doctrine-project.org/documentation/manual/1_2/en/dql-doctrine-query-language:subqueries
Try something like that:
$q = Doctrine_Query::create()
->delete('TableB b')
->where('b.id NOT IN (SELECT b.id FROM TableB b \
INNER JOIN b.TableA a WHERE b.date > NOW() AND a.channel_id = 10)')
->execute();
Its not necessary to write the query in plain sql, you can still use the QueryBuilder for that:
$entityManager = $this->getEntityManager();
$queryBuilder = $entityManager->createQueryBuilder();
$subQueryCityDataSources = $queryBuilder->getEntityManager()->createQueryBuilder()
->select('cds')
->from(CityDataSource::class, 'cds')
->where('cds.dataSource = :dataSource')
;
$queryBuilder->delete($entityClass, 'd');
$queryBuilder->where($queryBuilder->expr()->in('d.cityDataSource', $subQueryCityDataSources->getDQL()));
$queryBuilder->setParameter('dataSource', $dataSource);
$query = $queryBuilder->getQuery();
$query->execute();
This generates this query:
DELETE
AppBundle\Entity\ConcreteData\News d
WHERE
d.cityDataSource IN
(
SELECT
cds
FROM
AppBundle\Entity\CityDataSource cds
WHERE
cds.dataSource = :dataSource
)
Important note: you have to append all the parameters in the outer query.