```php
$this
           ->createQueryBuilder('o')
           ->select($qb->expr()->countDistinct('o.id'))
           ->innerJoin('o.elements', 'e');
```