createQueryBuilder('e') ; if(isset($params['user'])) { $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ; } if(isset($params['visitor'])) { $query->andWhere('e.visitor = :visitor')->setParameter('visitor', $params['visitor']) ; } $query->leftJoin('e.orderStatusHistories', 'orderStatusHistories') ->andWhere('SIZE(e.orderStatusHistories) = 0') ; return $query->getQuery()->getOneOrNullResult() ; } }