Jake N
Jake N

Reputation: 10583

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?

Upvotes: 20

Views: 18807

Answers (1)

Juan Sosa
Juan Sosa

Reputation: 5280

You can use ->andWhere like this:

->where("qi.content = " . $content->getId())
->andWhere("qi.queue = " . $child->getQueue()->getId());

Upvotes: 31

Related Questions