【发布时间】:2012-01-06 02:45:12
【问题描述】:
我是 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.
另外,在自定义存储库中或作为服务使用此查询时,哪种方法最好?
任何帮助表示赞赏。
【问题讨论】: