我有以下正确运行的查询:
$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”
任何人都有线索?如何回显左连接中的字段?
答案 0 :(得分: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返回对象数组并且连接表中的元素位于子数组
下时,这将起作用答案 1 :(得分: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
}