本文介绍了Symfony2 教义查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 symfony2 的新手,我不知道如何使用 createQuery() 在 symfony2 中编写以下查询
I'm new in symfony2 , I don't know how to write a below query in symfony2 using createQuery()
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
我使用了存储库类,在其中编写了一个函数
I used repository class,in which ,wrote a function
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();
}
当我使用此功能时,出现以下错误
when I used this function,I got the below error
[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.
另外,在自定义存储库中或作为服务使用此查询时,哪种方法最好?
Also which method is best using this query in a custom repository or as a service?
任何帮助表示赞赏.
推荐答案
如果您指定了引用实体的名称,doctrine2 中的 DQL 将不知道如何连接表.您只能使用一个实体及其字段(可能有关系).
DQL in doctrine2 won't know how to join tables if you specify the name of a referenced entity. You can only work with one entity and its fields (which may have relations).
select p,c,pr from RodasysfourmBundle:Post p inner join
p.Category c inner join c.Priority pr order by pr.priorityNumber desc
这篇关于Symfony2 教义查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!