【问题标题】:Doctrine error - expected end of string, got "ORDER"教义错误 - 预期的字符串结尾,得到“ORDER”
【发布时间】:2018-04-09 10:37:05
【问题描述】:

使用 Symfony 4 / Doctrine,我在这个查询中遇到了错误:

$this->createQueryBuilder('s')
        ->update()
        ->set('s.dateCreate', ':date_new')
            ->setParameter('date_new', date('Y-m-d H:i:s'))
        ->where('s.site = :site')
            ->setParameter('site', $site)
        ->orderBy('s.dateCreate', 'DESC')
        ->setMaxResults(1)
        ->getQuery()
        ->execute();

我收到了这个错误:

[Syntax Error] line 0, col 81: Error: Expected end of string, got 'ORDER'

如果我删除 orderBy,查询可以工作,但我只需要更新最后一个条目。看不出这里有什么问题..

【问题讨论】:

    标签: symfony doctrine


    【解决方案1】:

    您正在创建一个update 语句,在这种情况下,您无法在其中添加按函数排序。

    如果您想对结果进行排序,您需要创建 select 而不是更新到另一个查询中,您可以同时执行这两种操作,或者您需要进行子选择以仅更新 1 个结果,例如

    【讨论】:

    • 好的,我会尝试做一个子选择,谢谢,我不确定它是否可能
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 2019-12-20
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多