加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Symfony2教义查询

发布时间:2020-12-13 13:58:21 所属栏目:PHP教程 来源:网络整理
导读:我在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 我使用了存
我在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读