Doctrine Query Builder 不适用于 UPDATE 和 INNER JOIN [英] Doctrine Query Builder not working with UPDATE and INNER JOIN

查看:24
本文介绍了Doctrine Query Builder 不适用于 UPDATE 和 INNER JOIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的存储库中,我有这个查询:

In my repository I have this query:

$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 有什么问题吗?

I have checked the relation and it is right. Is there any issue using join in query update?

推荐答案

您不能对更新和删除查询使用联接.您必须使用子查询.

You can not use join on update and delete queries. You have to use subqueries.

更新和删除查询不支持连接,因为它不是支持所有 dbms.它不会在 Doctrine 1 或Doctrine 2. 但是,您可以通过使用子查询获得相同的效果.

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 个查询.

If you are using MySQL, using subqueries will not work. You will have then to use 2 queries.

在 MySQL 中,你不能修改一个表并从同一个表中选择一个子查询

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

这篇关于Doctrine Query Builder 不适用于 UPDATE 和 INNER JOIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆