Symfony2 Doctrine query(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 教义查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Symfony2 教义查询


基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01