2010-11-16 165 views
0

我有它正確地運行下面的查詢:Symfony的左連接查詢

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

,但是當我遍歷結果,並嘗試從左邊的領域加入:

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 
} 

,我得到了以下錯誤消息: 未知記錄屬性/相關組件「JOBTITLE」的「經驗」

任何人都得到了線索?我如何迴應左連接的字段?

+1

你需要做的是這樣'$ W- > EmploymentLevels-> employmentlevel' – 2010-11-16 14:19:36

+0

謝謝!那是我的問題。 – jorgen 2010-11-16 14:42:08

回答

0

解決方案:

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

?> 

這將作爲對象的symfony的回報陣列和加入的元素表子陣列下前來