Symfony2 / doctrine2 dql where field is not true

im having problems validating a boolean field with a "not true" condition im getting this error:

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

the query is built using dql. so in the code I added this as

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

      

executed request:

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

      

+3


source to share


2 answers


Usually, when you have a boolean value configured in Doctrine, you have an integer field with 0 or 1. It's much easier to check if the value is 0

or 1

.

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

      

or another solution:

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

      

or if you checked null



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

      

When you look at the page, you can see some expression. IS

cannot be used in this context.

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

And here is another link to show you how to use where in

andwhere not in

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

+3


source


Thanks guys. I have a nullable field. so i did it with this because i need everything that is not true.



$dql .= " AND (p.archived = 0 OR p.archived is null) ";

      

+1


source







All Articles