2010-11-16 131 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的回报阵列和加入的元素表子阵列下前来