Doctrine Query Builder不能与UPDATE和INNER JOIN协同工作 [英] Doctrine Query Builder not working with UPDATE and INNER JOIN

查看:147
本文介绍了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)
;

抛出此错误

  [语义错误]行0,col 66靠近'e2.id =:id':错误:'e2'未定义

我已经检查过关系,是对的。
有没有使用加入查询更新?

解决方案

Doctrine DQL不支持加入更新。 p>

尝试执行以下操作:

  $ qb = $ this-> getEntityManager() - > createQueryBuilder(); 
$ qb
- > update('MyBundle:Entity1','e1')
- > set('e1.visibile','1')
- > ;其中('e1.Entity2 =:id')
- > setParameter(id,123)
;

您可以直接将链接的实体的id作为主键,直接设置为如果是实体,教义将映射它。



我在查询中做的完全相同,它的工作原理。


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)
;

throw this error

[Semantical Error] line 0, col 66 near 'e2.id = :id': Error: 'e2' is not defined

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

解决方案

Doctrine DQL does not support join in update.

Try doing the following :

$qb = $this->getEntityManager()->createQueryBuilder();
$qb
    ->update('MyBundle:Entity1', 'e1') 
    ->set('e1.visibile', '1')
    ->where('e1.Entity2 = :id')
    ->setParameter("id", 123)
;

You can set the id, as long as it is the primary key, of the linked entity directly as if it was the entity, Doctrine will map it.

I'm doing the exact same thing in my queries and it works.

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

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