我在我的symfony2项目上试过了:
$em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery(
'SELECT v.voiture,o.offre,m.marque
FROM FrontOfficeBundle:Voiture v
INNER JOIN FrontOfficeBundle:OffreSpecial o on o.voiture_id = v.id
INNER JOIN FrontOfficeBundle:Marque m on m.id = v.marque_id'
);
$result = $query->getResult();
并得到那个错误:
[Syntax Error] line 0, col 122: Error: Expected Doctrine\ORM\Query\Lexer::T_WITH, got 'on'
甚至SQL查询都是正确的!请帮忙
答案 0 :(得分:1)
ON
您不需要INNER JOIN
选项。由于您在查询中指定了类FrontOfficeBundle:Voiture
,因此Doctrine查询语言已经知道您的关联的映射。
$em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery(
'SELECT v.voiture,o.offre,m.marque
FROM FrontOfficeBundle:Voiture v
INNER JOIN v.offreSpecial o
INNER JOIN v.marque m'
);
$result = $query->getResult();