Doctrine 1.2: Or clauses into andWhere

45 Views Asked by At

In Doctrine2, I have this code:

$em = $this->getDoctrine()->getEntityManager();
$qb = $em->createQueryBuilder();
$qb->from('TestBundle:Message', 'm')
       ->join('m.product', 'p')
       ->where('m.delDate IS NULL');
//create the OR request
$orModule = $qb->expr()->orx();
$orModule->add($qb->expr()->eq('p.module', ':module'));
$orModule->add($qb->expr()->isNull('p.module'));        
$qb->andWhere($orModule)->execute();

I want this code in Doctrine 1.2.

1

There are 1 best solutions below

0
Baptiste LARVOL-SIMON On

I'm not sure, but I think what you want to do may be something like (by memory and, yes, it's ugly) :

$q = new Doctrine_Query();
$q->from('MyTable t')
  ->where('t.name = ?', $name)
  ->andWhere('(TRUE')
  ->andWhere('t.firstname = ?', $var1)
  ->orWhere('t.firstname = ?', $var2)
  ->andWhere('TRUE)')
;

Good luck with this old friend!