加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

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

发布时间:2020-12-12 16:22:39 所属栏目:MsSql教程 来源:网络整理
导读:在我的存储库中,我有这个查询: $qb = $this-getEntityManager()-createQueryBuilder();$qb -update('MyBundle:Entity1','e1') -join('e1.Entity2','e2') -set('e1.visibile','1') -andWhere('e2.id = :id')-setParameter("id",123); 抛出这个错误 [Semantica
在我的存储库中,我有这个查询:
$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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读