Pages

Thursday, December 2, 2010

Symfony combine more than one table in Criteria

adding criteria with more than one table is easy than you think......

$id = '1';
$cri1 = new Criteria();
$cri1->add(TblName1Peer::ID,$id);
$cri_res1 = TblName1Peer::doSelectOne($cri1);


//if you you doSelectOne
$id = $cri_res1->getId();
$cri2 = new Criteria();
$cri2->add(TblName2Peer::ID,$id);
$cri_res = TblName2Peer::doSelect($cri2);
$this->ret_val = array_unique($cri_res);

//if you use doSelect as this
$cri_res = TblName1Peer::doSelect($cri1);
foreach($cri_res as $res)
{
$val []= TblName1Peer::retrieveByPk($res->getId());
}

$cri = new Criteria();
$cri->add(blName2Peer::ID,$val[0]);
$cri_res = TblName2Peer::doSelect($cri);
$this->ret_val = array_unique($cri_res);

Please notice me if something wrong.......

No comments:

Post a Comment