我是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.
还有,使用这个查询的最佳方法是在自定义仓库中使用还是作为服务使用?
任何帮助将不胜感激。