doyhq66282 2019-04-03 09:25
浏览 83
已采纳

我在symfony中查询时遇到了困难

I have Entity tag [ id , title ] and Entity annonce [id, title] .

Tag and annonce in relation ManyToMany,

So i have assiciation annonce_tag [ annonce_id, tag_id ]

I have only repository tag and repository annonce, i dont have annonce_tag repository

and i want to make query to get the TOP for example 3 tags most used

Who has suggestions to make this query

/---------Updated----------/

I have tried this one in Tag Repository but not working

   return $query = $this->createQueryBuilder('t')
        ->select('t.id','count(a)')
        ->innerJoin('t.annonces', 'a')
        ->getQuery()->getResult();
  • 写回答

3条回答 默认 最新

  • dpb56083 2019-04-03 09:52
    关注

    You could do something like that :

    SELECT tag.id, count(annonce.id) from App:Tag tag JOIN tag.annonces annonce GROUP BY tag.id ORDER BY count(annonce.id) desc
    

    You will get an ordered list of tags with the number of linked annonce for each

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?