简体   繁体   English

原则1.2:或和的子句

[英]Doctrine 1.2: Or clauses into andWhere

In Doctrine2, I have this code: 在Doctrine2中,我有以下代码:

$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. 我要在Doctrine 1.2中使用此代码。

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! 祝这个老朋友好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM