# Doctrine Query with subquery

I'm wondering if this is the right way to have a subquery in Doctrine. I have two entities, one called User and one called Log. There's a mapping from Log to User but not the other way around (ManyToOne).

I need a list of all users, which had log entries within a certain period. This is my current solution:

// UserRepository.php

/**
* @return User[]
*/
public function findLogUsersByCategory(int $category, \DateTime$start, \DateTime $end): array { return$this->createQueryBuilder('e')
->where('e.id IN (:users)')
->setParameter('users', $this->_em->createQueryBuilder() ->select('u.id') ->from(Log::class, 'l') ->join('l.user', 'u') ->where('l.category = :category') ->setParameter('category',$category)
->andWhere('l.created BETWEEN :start AND :end')
->setParameter('start', $start) ->setParameter('end',$end)
->orderBy('l.category', 'ASC')