Doctrine Query Builder not working with UPDATE and INNER JOIN

后端 未结 4 1375
没有蜡笔的小新
没有蜡笔的小新 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:12

    Doctrine DQL does not support join in update.

    Try doing the following :

    $qb = $this->getEntityManager()->createQueryBuilder();
    $qb
        ->update('MyBundle:Entity1', 'e1') 
        ->set('e1.visibile', '1')
        ->where('e1.Entity2 = :id')
        ->setParameter("id", 123)
    ;
    

    You can set the id, as long as it is the primary key, of the linked entity directly as if it was the entity, Doctrine will map it.

    I'm doing the exact same thing in my queries and it works.

提交回复
热议问题