2011-12-12 1 views
0

Propel ORM을 사용하여 Symfony 프로젝트에서 Criteria를 사용하여 복잡한 쿼리를 수행하려고합니다.Symfony Criteria 예기치 않은 동작에 참여하십시오.

내가 만들고 싶어 쿼리는 인간 즉,이다 :

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) 
여기

내가 만든 코드 및 작동하지 : 내가 SQL을 볼 수있는 $c->toString()을 행한 후

$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 
    } 

생성 및 나는 단지 $ apd 값을 보낼 때 SQL, 올바른, 또한 내가 $ apo 값을 보낼 때 보았다. 하지만 둘 다 보낼 때 $ apo AND 만 SQL에 표시됩니다.

$ c-> add (...) 호출이 고유 한 매개 변수와 동일하기는하지만 확실하지는 않습니다. 이 오류가 있습니까? 내 쿼리를 올바르게 생성하는 가장 좋은 방법은 무엇입니까?

감사합니다. : D

답변

0

예, Criteria 객체는 필드 당 하나의 조건 만 저장하므로 이전 호출을 무시합니다. 이 솔루션은 2 개 이상의 개별 기준 객체를 생성하고 기준으로 그들을 혼합하는 것입니다은 객체 :

//something like this 
$cron1 = $criteria->getNewCriterion(); 
$cron1->add($appPeer::NOMBRE_APLICACION,$apo,Criteria::LIKE);//4 
$criteria->add($cron); 
//and the same with the other criterion 

그러나, Propel15 쿼리 클래스 수준에서 작동 +, 여러 제한으로 업그레이드하는 것이 훨씬 쉬울 것 같은 필드에서 서로 재정의하지 마십시오.

호프가 도움이 되었으면 다니엘