我想算我的主题是多少次在我的博客中。DQL请求与LeftJoin
任何博客文章(法语文章)可以使用一个或多个主题。
所以我有一个表(多对多):
- themes_articles(id_theme,id_article)和:
- 主题(id_theme,nom_theme)
- 文章(博客文章)(id_article,说明.. 。)
在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.
如何在DQL请求中转换我的SQL请求?
谢谢你很多的帮助。
您好,我想你的要求,但我有这个错误 [语法错误] 0行,列87:错误:字符串应为结束,得到了“BlogBundle:主题” – devicz
凡位于你的实体?请提供此路径 – Tester
我添加了一个答案更多信息 – devicz