在我的存储库中,我有这个查询:
$qb = $this->getEntityManager()->createQueryBuilder(); $qb ->update('MyBundle:Entity1','e1') ->join('e1.Entity2','e2') ->set('e1.visibile','1') ->andWhere('e2.id = :id')->setParameter("id",123) ;
抛出这个错误
[Semantical Error] line 0,col 66 near 'e2.id = :id': Error: 'e2' is not defined
我检查了这种关系,这是正确的.
在查询更新中使用join是否有任何问题?
解决方法
您无法在更新和删除查询时使用联接.你必须使用子查询.
Joins are not supported on update and delete queries because it is not
supported on all dbms. It won’t be implemented in Doctrine 1 or
Doctrine 2. You can however get the same affect by using subqueries.
@L_404_0@
如果您使用的是MysqL,则使用子查询将无法正常工作.然后,您将使用2个查询.
In MysqL,you cannot modify a table and select from the same table in
a subquery