createQueryBuilder('tok'); $qb->innerJoin('tok.account', 'acc', Expr\Join::WITH, $qb->expr()->eq('acc.id', ':acc_id')); $qb->innerJoin('acc.application', 'app', Expr\Join::WITH, $qb->expr()->orx( $qb->expr()->eq('app.creator', 'acc.user'), $qb->expr()->isNull('app.creator') )); $qb->setParameter(':acc_id', $account->getId()); return $qb->getQuery()->getOneOrNullResult(); } }