, >=, !-6ren">
gpt4 book ai didi

mysql - symfony2/doctrine2 dql 其中字段不正确

转载 作者:可可西里 更新时间:2023-11-01 07:56:10 25 4
gpt4 key购买 nike

我在检查带有“不是真的”子句的 bool 字段时遇到了麻烦我收到此错误:

("[Syntax Error] line 0, col 510: Error: Expected =, <, <=, <>, >, >=, !=, got 'IS'")

查询是用 dql 构建的。所以在代码中我像这样添加了

$dql .= " AND p.archived IS NOT TRUE ";

执行的查询:

SELECT COUNT(p.id)
FROM Sandbox\WebsiteBundle\Entity\Pages\OfferPage p
INNER JOIN Kunstmaan\NodeBundle\Entity\NodeVersion nv WITH nv.refId = p.id
INNER JOIN Kunstmaan\NodeBundle\Entity\NodeTranslation nt WITH nt.publicNodeVersion = nv.id and nt.id = nv.nodeTranslation
INNER JOIN Kunstmaan\NodeBundle\Entity\Node n WITH n.id = nt.node WHERE n.deleted = 0
AND n.hiddenFromNav = 0
AND n.refEntityName = 'Sandbox\WebsiteBundle\Entity\Pages\OfferPage'
AND nt.online = 1 AND nt.lang = :lang AND p.archived IS NOT TRUE AND p.expirationDate >= :date ORDER BY p.price ASC

最佳答案

通常当你在 Doctrine 中配置了一个 bool 值时,你有一个带有 0 或 1 的整数字段。检查值是 0 还是 1 会容易得多。

$dql .= " AND p.archived = 0";

或其他解决方案:

$dql .= " AND p.archived = false";

或者如果您检查为 null

$dql .= " AND p.archived is null";

当您查看页面时,您会看到一些表情。 IS 不能在该上下文中使用。

http://doctrine1-formerly-known-as-doctrine.readthedocs.org/en/latest/en/manual/dql-doctrine-query-language.html

这是另一个链接,向您展示如何使用 where inwhere not in

http://www.ozonesolutions.com/programming/2011/09/symfony-doctrine-where-in-and-where-not-in-syntax/

关于mysql - symfony2/doctrine2 dql 其中字段不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30775386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com