1
$categories= array(3,20,24);    

$qb = $this->em->createQueryBuilder();
        $qb->select('p')
                ->from('\Entities\Productss', 'p')
                ->leftJoin('p.category', 'c')
                ->andWhere('p.id =?1')
                ->andWhere('p.id =?2')
                 ->andWhere('p.id =?2')
             ->setParameter(1, $categories[0])             
->setParameter(2, $categories[1])
->setParameter(3, $categories[2])

                ->getQuery();

this doesnt allow multiple wheres...

$categories is an array which consist of categories it must match in order to select correct products. such as shoes(3), black(20), small(24)

possible?

dean jase
  • 1,161
  • 5
  • 23
  • 38

1 Answers1

0

In the documentation of Doctrine I found this:

// Example - $qb->expr()->in('u.id', array(1, 2, 3))
// Make sure that you do NOT use something similar to $qb->expr()->in('value', array('stringvalue')) as this will cause Doctrine to throw an Exception.
// Instead, use $qb->expr()->in('value', array('?1')) and bind your parameter to ?1 (see section above)
public function in($x, $y); // Returns Expr\Func instance

// Example - $qb->expr()->notIn('u.id', '2')
public function notIn($x, $y); // Returns Expr\Func instance

It should be possible to put a subquery in this function. I never used it myself, but give it a try.

EDIT

I understand it is a many-to-many relation. In this case you should use the MEMBER OF option.

So like:

$qb->...
   ->andWhere("p.category MEMBER OF ?1")
   ->andWhere("p.category MEMBER OF ?2")
   ->...
Rene Terstegen
  • 7,911
  • 18
  • 52
  • 74