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?
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With