0
我正在嘗試使用Propel ORM在Symfony項目中使用Criteria進行復雜查詢。Symfony標準加入意外行爲
我要讓查詢是,在人類的話:
Select from the 'interface' table the registers that:
- 1 are associated with a process (with a link table)
- 2 have a name similat to $name
- 3 its destiny application's name is $apd (application accecible by foreign key)
- 4 its originapplication's name is $apo (application accecible by foreign key)
在這裏,我所做的代碼,而不是工作:
$c = new Criteria();
$c->addJoin($linkPeer::CODIGO_INTERFASE,$intPeer::CODIGO_INTERFASE); //1
$c->add($linkPeer::CODIGO_PROCESONEGOCIO,$this->getCodigoProcesonegocio());//1
if($name){
$name = '%'.$name.'%'; //2
$c->add($intPeer::NOMBRE_INTERFASE,$name,Criteria::LIKE); //2
}
if($apd){
$apd = '%'.$apd.'%'; //3
$c->addJoin($appPeer::CODIGO_APLICACION,$intPeer::CODIGO_APLICACION_DESTINO);//3
$c->add($appPeer::NOMBRE_APLICACION,$apd,Criteria::LIKE); //3
}
if($apo){
$apo = '%'.$apo.'%';//4
$c->addJoin($appPeer::CODIGO_APLICACION,$intPeer::CODIGO_APLICACION_ORIGEN);//4
$c->add($appPeer::NOMBRE_APLICACION,$apo,Criteria::LIKE);//4
}
之後,我做了$c->toString()
看到SQL生成,我看到,當我只發送一個$ apd值時,SQL是正確的,當我發送$ apo值也是。但是,當我發送兩個,只有$ apo AND
apears在SQL上。
我猜它是因爲$ c-> add(...)調用與一個不同的參數相同,但根本不確定。這是錯誤嗎?什麼是正確生成我的查詢的最佳方法?
非常感謝您的時間! :D