Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple WHERE using QueryBuilder

When using the following only the last where is added to my query;

$qb = $this->getEntityManager()->createQueryBuilder();

$qb->select(array('qi'))
    ->from('Table:Qi', 'qi')
    ->where("qi.content = " . $content->getId())
    ->where("qi.queue = " . $child->getQueue()->getId());

I had to do this to make it take notice of both

$qb->select(array('qi'))
    ->from('Table:Qi', 'qi')
    ->where("qi.content = " . $content->getId() . 
                 " AND qi.queue = " . $child->getQueue()->getId());

This does not seem right? How can I use the first approach with multiple where calls?

like image 257
Jake N Avatar asked Mar 08 '13 18:03

Jake N


1 Answers

You can use ->andWhere like this:

->where("qi.content = " . $content->getId())
->andWhere("qi.queue = " . $child->getQueue()->getId());
like image 163
Juan Sosa Avatar answered Sep 18 '22 15:09

Juan Sosa