【问题标题】:DQL Query - Right JoinDQL 查询 - 右连接
【发布时间】:2017-06-14 10:44:48
【问题描述】:

我想计算我的主题在我的博客中使用了多少次。

任何博客文章(法语文章)都可以使用一个或多个主题。

所以我有一张桌子(ManyToMany):

  • themes_articles (id_theme,id_article) 并且:

  • 主题(id_theme,nom_theme)

  • 文章(博客文章)(id_article、description ...)

在 SQL 中,我这样做:

SELECT T.id,nom_theme,count(A.themes_id) from themes_articles A right join themes T on T.id=A.themes_id group by nom_theme

它有效,但是当我想在 DQL 中使用右连接时,它有点难。我切换了我的两个表以使用左连接,但我不知道如何在此处使用我的关系表(themes_articles)。

我试过这样的:

 $query = $this->createQueryBuilder('')
->select(array('T.id', 'nomTheme', 'count(A.themes_id) as nombre'))
->from('themes', 'T')
->leftJoin('themes_articles', 'A', 'WITH', 'T.id= A.themes_id')
->groupBy('nom_theme');
    return $query->getQuery()->getResult();

但它不起作用。

[Semantical Error] line 0, col 93 near 'themes_articles': Error: Class 'themes_articles' is not defined.

如何将我的 SQL 请求转换为 DQL 请求?

非常感谢您的帮助。

【问题讨论】:

  • “不起作用”是什么意思?你检索错误吗?
  • 嗨。是的,我有这个错误:[Semantical Error] line 0, col 93 near 'themes_articles': Error: Class 'themes_articles' is not defined.

标签: symfony dql


【解决方案1】:

尝试改变这个:

->leftJoin('themes_articles', 'A', 'WITH', 'T.id= A.themes_id')

到这里:

->leftJoin('YourBundle:themes_articles', 'A', 'WITH', 'T.id= A.themes_id')

【讨论】:

  • 嗨,同样的事情,[语义错误]第 0 行,'BlogBu​​ndle:themes_articles' 附近的第 93 列:错误:未定义类'BlogBu​​ndle\Entity\themes_articles'。
猜你喜欢
  • 2015-08-18
  • 2012-10-21
  • 2012-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-21
  • 1970-01-01
相关资源
最近更新 更多