我在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将不知道如何连接表.您只能使用一个实体及其字段(可能有关系).
select p,pr from RodasysfourmBundle:Post p inner join p.Category c inner join c.Priority pr order by pr.priorityNumber desc