Doctrine查询生成器不使用UPDATE和INNER JOIN [英] Doctrine Query Builder not working with UPDATE and INNER JOIN

查看:311
本文介绍了Doctrine查询生成器不使用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?

推荐答案

不能在更新和删除查询时使用join。您必须使用子查询。

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,则使用子查询将无法使用。

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


在MySQL中,您无法修改表格并从
a中选择相同的表格子查询

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查询生成器不使用UPDATE和INNER JOIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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