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

doctrine2 – doctrine 2查询生成器和连接表

发布时间:2020-12-12 16:14:02 所属栏目:MsSql教程 来源:网络整理
导读:你好,我尝试得到我的主页中每个帖子的所有评论 return $this-createQueryBuilder('c')-select('c')-from('SdzBlogBundleEntityCommentaire','c') -leftJoin('a.comments','c')-getQuery()-getResult() ; 但是我会发现这个错误 [Semantical Error] line 0,c
你好,我尝试得到我的主页中每个帖子的所有评论
return 
$this->createQueryBuilder('c')
->select('c')
->from('SdzBlogBundleEntityCommentaire','c')                
->leftJoin('a.comments','c')->getQuery()->getResult() ;

但是我会发现这个错误

[Semantical Error] line 0,col 58 near '.comments c,': Error:
Identification Variable a used in join path expression but was not defined before.

PS:映射是正确的,我可以看到页面的文章与其评论

解决方法

如果这仍然给您提供问题,请使用Doctrine 2.1文档中的示例中的语法查询.

我假设您的查询位于自定义存储库方法中,’a’是“文章”的缩写.

$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();

$qb->select(array('a','c'))
   ->from('SdzBlogBundleEntityArticle','a')
   ->leftJoin('a.comments','c');

$query = $qb->getQuery();
$results = $query->getResult();

return $results;

(编辑:李大同)

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

    推荐文章
      热点阅读