数据库 – Doctrine Query Builder不使用UPDATE和INNER JOIN

前端之家收集整理的这篇文章主要介绍了数据库 – Doctrine Query Builder不使用UPDATE和INNER JOIN前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的存储库中,我有这个查询
$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.

http://www.doctrine-project.org/jira/browse/DC-646

如果您使用的是MysqL,则使用子查询将无法正常工作.然后,您将使用2个查询.

In MysqL,you cannot modify a table and select from the same table in
a subquery

http://dev.mysql.com/doc/refman/5.0/en/subqueries.html

原文链接:https://www.f2er.com/mssql/83255.html

猜你在找的MsSQL相关文章