Multiple WHERE using QueryBuilder
Asked Answered
B

1

19

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?

Bugle answered 8/3, 2013 at 18:32 Comment(0)
B
30

You can use ->andWhere like this:

->where("qi.content = " . $content->getId())
->andWhere("qi.queue = " . $child->getQueue()->getId());
Barcellona answered 8/3, 2013 at 18:35 Comment(1)
you actually dont need to use ->where before andWhere. You can alway use ->andWhere();Rebeckarebeka

© 2022 - 2024 — McMap. All rights reserved.