2011-08-16 37 views
2

現在,下面的代碼查找數據庫中的author_id和target_object_id,並且要求兩者匹配,才能被查詢檢索到。我希望它是WHERE author_id='x' || target_object_id='y'而不是它是& &默認情況下,這是下面的代碼。如何在使用Symfony的Propel查詢中使用OR語句

我看過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

您可以使用該網站把查詢到的Propel對象:HTTP://推進。 jondh.me.uk/criteria/analyse –

回答

0

您需要創建標準的對象從您的標準對象和合並他們在您需要的條件:

//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); 
相關問題