我使用此代碼在doctrine2中執行zf2應用程序中的原生sql查詢。doctrin2 zf2原生sql已加入表
我使用此代碼
$rsm = new ResultSetMapping();
$rsm->addEntityResult('Admin\Entity\SkillsExperience', 'skexp');
$rsm->addFieldResult('skexp', 'id', 'id');
$rsm->addFieldResult('skexp', 'idExperience', 'id_experience');
$rsm->addFieldResult('skexp', 'idSkillsDetails', 'id_skills_details');
$rsm->addJoinedEntityResult('Admin\Entity\SkillsDetails', 'skd','skexp','idSkillsDetails');
$rsm->addFieldResult('skd','description','description');
$rsm->addFieldResult('skd','idSkill','id_skill');
$sql = "
SELECT
skexp.id,
skexp.id_experience,
skexp.id_skills_details,
skd.description,
skd.id_skill
FROM skills_experience skexp
INNER JOIN skills_details skd
ON skd.id = skexp.id_skills_details
WHERE skexp.id_experience = $id_experience
ORDER BY skd.id_skill
";
$query = $this->getEntityManager()
->createNativeQuery($sql, $rsm)
->setParameter(1,$id_experience);
echo $query->getSQL();
$skexp = $query->getResult();
var_dump($skexp);
這是結果
陣列(1){ [0] => 對象(管理員\實體\ SkillsExperience)#471(3){ [「id」:「Admin \ Entity \ SkillsExperience」:private] => string(1)「1」 [「idExperience」:「Admin \ Entity \ SkillsExperience」:private] => NULL [「idSkillsDetails 「:」管理\實體\技能體驗「:private] => object(Admin \ Entity \ SkillsDetails)#473(3){」id「:」Admin \ Entity \ SkillsDetails「:private] => NULL [」description「管理員\實體\ SkillsDetails 「:私人] => 串(18) 」skillsname「 [」 idSkill 「:」 管理員\實體\ SkillsDetails「:私人] => NULL } } }
我期望idSkillsDetails中的「Admin \ Entity \ SkillsDetails」,但它不是
我無法獲得
skd.description, skd.id_skill
哪能?
感謝