symfony - 使用连接表更新学说

标签 symfony doctrine-orm

我正在尝试更新注释实体中的字段“注释”,该字段与“ElementModule”和“Inscription”具有ManyToOne(双向)关系,实体“Inscription”与“Etudiant”实体具有ManyToOne关系

我尝试了这个 DQL 查询:

$query = $this->_em->createQuery('update UaePortailBundle:Note u JOIN u.inscription i JOIN u.elementmodule e join i.etudiant et set u.note = ?3
                                                where et.id = ?1 and e.id = ?2 ');
    $query->setParameter(1, $etudiant);
    $query->setParameter(2, $element);
    $query->setParameter(3, $note);
    $resultat = $query->execute();

我收到此错误

[Syntax Error] line 0, col 50: Error: Expected Doctrine\ORM\Query\Lexer::T_EQUALS, got 'i'

最佳答案

LEFT JOIN,或者特别是 JOIN 仅在 MySQL 的 UPDATE 语句中受支持。 DQL 抽象了常见 ansi sql 的子集,因此这是不可能的。尝试使用子选择或 IDENTITY(您必须使用最新版本的 Doctrine 2.2.2):

createQuery('update UaePortailBundle:Note u set u.note = ?3
             where IDNETITY(u.inscription) = ?1 and IDENTITY(u.elementmodule) = ?2 ');

关于symfony - 使用连接表更新学说,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10744432/

相关文章:

php - Twig:渲染 Controller 与宏

sql - Doctrine DQL 每组最大 n

MySQL 和 Symfony2 : Exceptions and Hair Loss

doctrine-orm - Symfony & Doctrine 2/加速查询

php - 在 Doctrine 实体中访问 Symfony2 服务层?

symfony - 使用 Doctrine 和 Symfony2 进行数据库搜索

symfony - PDOException 找不到驱动程序

php - Symfony:在防火墙后路由的 SecurityContext 中找不到 token

php - Symfony2 应用程序在每次请求时解析 YML

php - 在隔离包中注册 Symfony Hydrators