我很难用“不是真”子句来检查布尔字段,因为我得到了这个错误:
(“语法错误第0行,第510行:错误:预期=,<,<=,<>,>,>=,!=,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发布于 2015-06-11 08:35:15
通常,当您在Doctrine中配置了一个布尔值时,就会有一个带有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 in和where not in
http://www.ozonesolutions.com/programming/2011/09/symfony-doctrine-where-in-and-where-not-in-syntax/
发布于 2015-06-11 08:39:32
谢谢各位。我有一个可空的字段。所以我做了这件事,因为我需要的都不是真的。
$dql .= " AND (p.archived = 0 OR p.archived is null) ";https://stackoverflow.com/questions/30775386
复制相似问题