symfony - Two foreign keys to the same same table in Symfony2 -
if have 2 foreign keys, how create querybuilder sql:
select * mappaths m join unitids n on (m.ref_unitids2 = n.id or m.ref_unitids1 = n.id) m.id = 2
for design querybuilder not think correct:
$query = $qb->select('m') ->from('apimapbundle:mappaths','m') ->innerjoin('m.refunitids1','u') ->innerjoin('m.refunitids2','v') ->where('m.id=:test') ->setparameter('test',1) ->getquery() ->getresult() ; $users = $reposity->getresult(); return $users; $dql = $qb->getdql(); echo $dql; $result = $query->getresult(); echo $result;
any idea how can solve above query using querybuilder?
your example not work both innerjoins have realised return row.
something may work (i have not tested this):
$query = $qb->select('m') ->from('apimapbundle:mappaths','m') ->join('yourbundle:yourotherentity', 'u', 'with', $qb->expr()->orx('m.refunitids1 = u.id','m.refunitids2 = u.id')) ->where('m.id=:test') ->setparameter('test',1) ->getquery() ->getresult() ;
Comments
Post a Comment