1
votes

I want to get Characteristic by category.

I got this error

[Syntax Error] line 0, col 95: Error: Expected Doctrine\ORM\Query\Lexer::T_OPEN_PARENTHESIS, got 'categories'

error screenshot

Relation in Characteristic Entity:

/**
 * @ORM\ManyToMany(targetEntity="App\Entity\Category", inversedBy="characteristics")
 */
private $categories;

My query builder function:

$this->createQueryBuilder('characteristic')
 ->leftJoin('characteristic.categories', 'categories')
 ->andWhere(':category in categories')
 ->setParameter('category', $category)
 ->getQuery()
 ->getOneOrNullResult();
1
I think you might have to switch the IN statement: stackoverflow.com/a/11640202/4457798 - Spomsoree

1 Answers

0
votes

Thanks for commenting.

I solved that problem by using MEMBER OF statement.

Here is the code:

$this->createQueryBuilder('characteristic')
 ->andWhere(":category MEMBER OF characteristic.categories")
 ->setParameter('category', $category)
 ->getQuery()
 ->getOneOrNullResult()
        ;