开发者

Adding a count of all the related items for a doctrine2 query

开发者 https://www.devze.com 2023-03-23 05:43 出处:网络
I\'ve this Query on doctrine2 that basically returns the different tags a Host have. May not be the best way to do it but it works. See, the tag<->ticket<->host are both manytomany relations.

I've this Query on doctrine2 that basically returns the different tags a Host have. May not be the best way to do it but it works. See, the tag<->ticket<->host are both manytomany relations.

$qb-开发者_StackOverflow>select('t')
    ->from('App\Entity\Tag', 't')
    ->join('t.tickets', 'p')
    ->join('p.hosts', 'b')
    ->where('b.id = '. $this->host->getId())
    ->add('orderBy', 't.name ASC');

As i said the problem is not this query (that works!), but i would like to add a count there to see how many tickets the returned Tag has. Been tryin all day with:

$qb->expr()->countDistinct("p.id");

Or even with DQL but can't make it work, would appreciate any suggestion.

Regards,


You could try:

$qb->addSelect(
  $qb->expr()->countDistinct("p.id")
);
0

精彩评论

暂无评论...
验证码 换一张
取 消