Doctrine Query Builder not working with UPDATE and INNER JOIN

后端 未结 4 1371
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 03:40

In my repository I have this query:

$qb = $this->getEntityManager()->createQueryBuilder();
$qb
    ->update(\'MyBundle:Entity1\', \'e1\') 
    ->         


        
4条回答
  •  暖寄归人
    2020-12-19 04:20

    try using a subquery instead Join will not work in DQL while you re doing an update:

    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:

    $qb = $this->getEntityManager()->createQueryBuilder();
        $qb ->update('MyBundle:Entity1', 'e') 
            ->set('e.visibile', '1')
            ->where('e.id IN (SELECT e1.id FROM Entity1 e1 INNER JOIN e2.Entity2 e2 WHERE e2 = :id')
            ->setParameter("id", 123);
    

提交回复
热议问题