【发布时间】: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.