Query with GROUP BY


I have a Model with Data in a Timeline. Now i want in the Repository a findAll Method that only shows the currently active objects. They are defined with a tlAb (begin) and tlBis (end) where the end date can be set, but does not have to.
All belonging objects share same uid.
Now i want to show only the currently active versions of those uid’s

        $query->lessThanOrEqual('tlAb', $time),
            $query->greaterThanOrEqual('tlBis', $time),
            $query->equals('tlBis', null)
    'uid' => QueryInterface::ORDER_ASCENDING,
    'tlAb' => QueryInterface::ORDER_DESCENDING

This query actually shows all versions with tlAb in the past and tlBis in the future or not set.
But i want to narrow it down to only the newest version. So in SQL i would just do a


But the GroupBy is not accessible through QueryInterface.

How is the best way to do this grouping?


You could use DQL, that provides GROUP BY. See createDqlQuery($dqlString) in Flow\Persistence\Doctrine\Repository.