Symfony1 如何使用Symfony在推进查询中使用OR语句

Symfony1 如何使用Symfony在推进查询中使用OR语句,symfony1,propel,Symfony1,Propel,现在,下面的代码在数据库中查找author_id和target_object_id,并要求两者匹配,以便查询检索。我希望它是author_id='x'| target_object_id='y'的位置,而不是默认情况下的&&位置,这就是下面的代码所做的 我看过《推进》和《Symfony手册》,它们对我没有帮助 $c = new Criteria(); $c->add("type", GVCCommentPeer::TYPE_PRIVATE_MESSAGE); $c->add("aut

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

我看过《推进》和《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());

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

//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);

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

//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);

您可以使用此网站将查询转换为推进对象:您可以使用此网站将查询转换为推进对象: