如何在使用Symfony的Propel查询中使用OR语句

时间:2011-08-16 18:23:59

标签: symfony1 propel

现在,下面的代码在数据库中查找author_id和target_object_id,并且要求两者匹配,以便由查询进行检索。我希望它是WHERE author_id='x' || target_object_id='y'而不是&&默认情况下,这是下面的代码。

我看过Propel和Symfony手册,他们没有帮助我。

$c = new Criteria();
$c->add("type", GVCCommentPeer::TYPE_PRIVATE_MESSAGE);
$c->add("author_id", $this->myprofileid);
$c->add("target_object_id", $this->profile->getId());

1 个答案:

答案 0 :(得分:0)

您需要从Criteria对象创建Criterion对象,并根据您需要的条件合并它们:

//create your Criteria
$c = new Criteria();
$c->add("type", GVCCommentPeer::TYPE_PRIVATE_MESSAGE);

//create 2 Criterion objects
$c1 = $c->getNewCriterion("author_id", $this->myprofileid);
$c2 = $c->getNewCriterion("target_object_id", $this->profile->getId());

// merge the two fields on OR
$c1->addOr($c2);

//bind
$c->add($c1);

$result = YOURPEERHEREPeer::doSelect($c);
相关问题