Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2 UPDATE with LEFT JOIN

SELECT - all right, no errors

$em = $this->get('doctrine.orm.entity_manager');

$query = $em->createQuery("
    SELECT c
    FROM MyDemoBundle:Category c
    LEFT JOIN c.projects p
    WHERE c.isActive = true
    AND p.id = 1
");
$result = $query->getResult();

UPDATE - exception [Semantical Error]

$query = $em->createQuery("
    UPDATE MyDemoBundle:Category c
    LEFT JOIN c.projects p
    SET c.isActive = false
    WHERE p.id = ?1
");
$query->setParameter(1, $id);
$query->execute();
like image 412
qbbr Avatar asked Nov 14 '22 00:11

qbbr


1 Answers

LEFT JOIN, or JOINs in particular are only supported in UPDATE statements of MySQL. DQL abstracts a subset of common ansi sql, so this is not possible. Try with a subselect:

UPDATE MyDemoBundle:Category c SET c.isActive = false WHERE ?1 MEMBER OF c.projects;

(MEMBER OF is actually turning into a subselect here). I am not 100% sure if this works, but it is more likeli than the join.

like image 100
beberlei Avatar answered Dec 28 '22 14:12

beberlei