Doctrine2 [Syntax Error] Error: Expected Literal, got '-'
doctrine-orm, symfony
Solution
Should do the trick :
$queryBuilder = $this->_em->createQueryBuilder();
$queryBuilder
->select('n')
->from('MyBundle:Table', 'n')
->where('n.status IN (:status)')
->setParameter('status', array(1, -1));
Problem
I am using doctrine2 with symfony2 and I am trying to perform a simple select query: I want to run: ``` SELECT * FROM table WHERE status in (1, -1) ``` This PHP code: ``` $queryBuilder = $this->_em->createQueryBuilder(); $queryBuilder ->select('n') ->from('MyBundle:Table', 'n') ->where('n.status IN (1, -1)'); return $queryBuilder->getQuery()->getResult(); ``` Gives the following exception: ``` [Syntax Error] line 0, col 96: Error: Expected Literal, got '-' ``` This is the attribute definition within the entity: ``` /** * @var integer * * @ORM\Column(name="status", type="integer", nullable=true) */ private $status; ``` If I use only positive numbers within the `in` argument, it will work. The exception only happens with negative numbers. What causes this exception?