我在symfony2中是新的,我不知道如何使用createQuery()在symfony2中写下面的查询,
select * from Post inner join Category on Post.category_id=Category.id inner join Priority on Post.priority_id=Priority.id order by priority_number desc
我使用了存储库类,其中写了一个函数
public function findAllOrderedByPriorityPost() { return $this->getEntityManager() ->createQuery('select p,c,pr from RodasysfourmBundle:Post p inner join RodasysfourmBundle:Category c inner join RodasysfourmBundle:Priority pr order by pr.priorityNumber desc') ->getResult(); }
[Semantical Error] line 0,col 85 near 'c inner join': Error: Identification Variable RodasysfourmBundle:Category used in join path expression but was not defined before.
任何帮助赞赏.
如果指定引用实体的名称,doctrine2中的DQL将不知道如何连接表.您只能使用一个实体及其字段(可能有关系).
原文链接:https://www.f2er.com/php/139378.htmlselect p,pr from RodasysfourmBundle:Post p inner join p.Category c inner join c.Priority pr order by pr.priorityNumber desc