symfony - symfony2 leftjoin condition on right - losing data -


i have 3 entities

. "ejuridique" has 1 relation "onetomany" with

. "project" has 1 relation "onetomany" with

. "photo"

when 1 query on "ejuridique" , cascading left join on "project" , after on "photo", adding conditions on projects , photos, lose "ejuridiques" not have projects. keep "ejuridique" if not have projects.

i have tried solutions given other questions similar 1 found on forums, still not work.

with querybuilder in repository

class ejuridiquerepository extends entityrepository {     public function myfindall()         {             $qb = $this->createquerybuilder('a')                 ->leftjoin('a.projets', 'pr' )                 ->leftjoin('pr.photos', 'ph' )                 ->where('pr.projetposition = :position_pr')                 ->andwhere('ph.position = :position_ph')                 ->setparameters(array('position_pr'=> "1",'position_ph'=> "1"))                 ->addselect('pr')                 ->addselect('ph');              return $qb->getquery()                   ->getresult();         } } 

or dql

$dql = "select e,pr,ph chlwebsitesbundle:ejuridique e left join e.projets pr   left join pr.photos ph pr.projetposition=1 , ph.position=1";  $query = $this->getdoctrine()->getentitymanager()->createquery($dql); $ejuridiques = $query->getresult(); 

i lose data both 2 methods.

thank in advance helping me

the problem query where clause has conditions project , photo entities, entity these relations null not returned.

you need put these conditions in left join i.e.

$qb = $this->createquerybuilder('a') ->leftjoin('a.projets', 'pr' \doctrine\orm\query\expr\join::with, 'pr.projetposition = :position_pr') ->leftjoin('pr.photos', 'ph', \doctrine\orm\query\expr\join::with, 'ph.position = :position_ph' ) ->setparameters(array('position_pr'=> "1",'position_ph'=> "1")) ->addselect('pr') ->addselect('ph'); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -