我想从多个表中获取数据,但我没有在symfony3 doctrine中获得正确的查询。请帮帮我。
我写了我的学说查询如下 -
$q = $this-> getDoctrine()-> getManager();
$query = $q->createQuery('
SELECT p.firstname , p.lastname , l.language
from UserBundle:Post p
from UserBundle:Language l
from UserBundle:UserLanguage u
where p.id = u.id and l.id = u.languageid
');
return $queryBuilder->getQuery()->getResult();
}
答案 0 :(得分:0)
我终于能够解决这个问题了。这是用于从给定条件的多个表中获取不同列的dql查询。
$em = $this -> getDoctrine()->getManager();
$res = $em->createQuery(' SELECT p.firstname , p.lastname , l.language from UserBundle:Post p Join UserBundle:UserLanguage u with p.id = u.userid join UserBundle:Language l with l.id = u.languageid');
$result = $res->getResult();
return $this->render('UserBundle:Default:showLanguage.html.twig', array('user' => $result));