我想算我的主題是多少次在我的博客中。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