I would personally avoid using the annotation order directly. Yes, you should query, as if you were using raw SQL without Doctrine at all.
However, I would not have done it at that moment, but even earlier. In your particular case, I would create a ViewRepository class:
class ViewRepository extends EntityRepository { public function findWithVersionsNewerThan($id, \DateTime $time) { return $this->createQueryBuilder('view') ->addSelect('version') ->join('view.versions', 'version') ->where('view.id = :id') ->andWhere('version.timeMod > :time') ->setParameter('time', $time) ->setParameter('id', $id) ->getQuery() ->getOneOrNullResult(); } }
Now you can do:
$yourDateTime = // Calculate it here ... ; $view = $em->getRepository("GutensiteCmsBundle:View\ViewVersion")->findWithVersionsNewerThan($yourDateTime); $versions = $view->getVersions(); // Will only contain versions newer than datetime provided
I am writing code from the top of my head here, so it is unfortunate if a syntax or named error is stitched.
source share