2013-03-08 5 views
11

Quando si utilizza quanto segue, solo l'ultimo where viene aggiunto alla mia query;Multiple WHERE using QueryBuilder

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

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

ho dovuto fare questo per renderlo prendere atto sia della

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

Questo non mi sembra giusto? Come posso utilizzare il primo approccio con più chiamate where?

risposta

20

È possibile utilizzare ->andWhere come questo:

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

Superb - grazie –

+0

effettivamente dont ** ** necessità di usare '-> WHERE' prima di' andWhere'. Puoi sempre usare '-> andWhere();' – xDaizu