2010-11-16 4 views
0

J'ai la requête suivante qui exécute correctement:Symfony jointure gauche requête

$q = $this->createQuery('e') 
    ->where('e.Persons_idUser =?', $request) 
    ->leftJoin('e.JobTitles jt') 
    ->leftJoin('e.EmploymentLevels el'); 

mais quand je suis itérer le résultat et essayer d'accéder aux champs de la jointure gauche:

foreach ($work as $w){ 
    echo $w->employername; 
    echo $w->jobtitle; // this is from the left join 
    echo $w->employmentlevel; // this is from the left join 
} 

Je reçu le message d'erreur suivant: propriété d'enregistrement Inconnu/composante liée « jobTitle » sur « Expériences »

Quelqu'un at-il un indice? Comment faire écho à un champ d'une jointure à gauche?

+1

Vous aurez besoin de faire quelque chose comme '$ W- > EmploymentLevels-> employmentlevel' –

+0

Merci! C'était mon problème. – jorgen

Répondre

0

Solution:

foreach ($work as $w){ 
echo $w->employername; 
echo $w->JobTitles->jobtitle; // this is from the left join 
echo $w->EmploymentLevels->employmentlevel; // this is from the left join 
} 
1
<?php 
    foreach ($work as $w){ 
     echo $w->employername; 
     foreach($w->JobTitles as $job){ 
      echo $job->jobtitle; // this is from the left join 
     } 
     foreach($w->EmploymentLevels as $employ){ 
      echo $employ->employmentlevel; // this is from the left join 
     } 
    } 

?> 

Cela fonctionne comme tableau des rendements symfony d'objets et les éléments de table de jointure viennent sous tableau d'enfants

Questions connexes