Reputation: 11
I get this a [Syntax Error] line 0, col 95: Error: Expected Literal, got 'value'
error when I try to execute the following query:
$qb = $this->createQueryBuilder('a');
$qb
->join('a.categories', 'cat')
->where($qb->expr()->in('cat.name', $category));
return $qb->getQuery()->getResult();
The mapped field is as followed:
/**
* @ORM\ManyToMany(targetEntity="Camten\TestBundle\Entity\Category", cascade={"persist"}, inversedBy="articles")
*/
private $categories;
Thought it was a problem with the data type but I really can't find what's wrong.
Upvotes: 1
Views: 5742
Reputation: 8164
You have to use setParameter()
to bind parameter to dql variables
See below,
qb = $this->createQueryBuilder('a');
$qb
->join('a.categories', 'cat')
->where('cat.name = :nameParam')
->setParameter('nameParam', $category);
return $qb->getQuery()->getResult();
(I named it nameParam
to show it has nothing to do with cat.name
)
If you want to use the $qb->expr()->
* methods you should use eq()
and not in()
qb = $this->createQueryBuilder('a');
$qb
->join('a.categories', 'cat')
->where($qb->expr()->eq('cat.name',':nameParam'))
->setParameter('nameParam', $category);
return $qb->getQuery()->getResult();
Upvotes: 3