我想统计我的博客中使用了多少次我的主题。DQL查询 - 右键加入
任何博客文章(法语文章)都可以使用一个或多个主题。
所以我有一个表(多对多):
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.
如何在DQL请求中转换我的SQL请求?
非常感谢您的帮助。
这是什么意思 “不工作”?你检索错误吗? –
嗨。 是的,我有这个错误: [语义错误] line 0,col 93 near'themes_articles':Error:Class'themes_articles'is not defined。 – devicz