Fix query to have all tags taken into account on recipe search
<?php

namespace AppBundle\Entity;

/**
 * RecipeRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class RecipeRepository extends \Doctrine\ORM\EntityRepository
{
    public function searchRecipes($categoryId, $tags)
    {
        $queryBuilder = $this->createQueryBuilder('r');
        $queryBuilder->leftJoin('r.category', 'category');
        $queryBuilder->where('category.id = :categoryId');
        $queryBuilder->setParameter(':categoryId', $categoryId);
        
        $queryBuilder->leftJoin('r.tags', 't');
        $queryBuilder->andWhere('t.id IN(:tags)');
        $queryBuilder->setParameter('tags', array_values($tags->toArray()));
        
        $queryBuilder->having('COUNT(t) >= :nbTags');
        $queryBuilder->setParameter('nbTags', count($tags));
        
        return $queryBuilder->getQuery()->getResult();
    }
}

<?php

namespace AppBundle\Entity;

/**
 * RecipeRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class RecipeRepository extends \Doctrine\ORM\EntityRepository
{
    public function searchRecipes($categoryId, $tags)
    {
        $queryBuilder = $this->createQueryBuilder('r');
        $queryBuilder->leftJoin('r.category', 'category');
        $queryBuilder->where('category.id = :categoryId');
        $queryBuilder->setParameter(':categoryId', $categoryId);
        
        $queryBuilder->leftJoin('r.tags', 't');
        $queryBuilder->andWhere('t.id IN(:tags)');
        $queryBuilder->setParameter('tags', array_values($tags->toArray()));
        
        return $queryBuilder->getQuery()->getResult();
    }
}
