Symfony2 doctrine嵌套条件(和Where)与join

时间:2015-11-18 06:58:31

标签: php symfony doctrine-orm query-builder

我希望使用QueryBuilder

执行此类操作
$query = $qb
        ->select('u')
        ->from('AppBundle:School', 'u')
        ->where('u.superAdmin = :user')
        ->andWhere(
            $qb->join('u.admins', 'admins')
                ->where('admins = :user'))
        ->setParameters(array(':user' => $userArray))
        ->getQuery();

有人可以告诉我,我的工作方式如何?

1 个答案:

答案 0 :(得分:2)

在您的SchoolRepository.php中:

$query = $this->createQueryBuilder('u')
    ->where('u.superAdmin = :user')
    ->leftJoin('u.admins', 'a')
    ->andWhere('a = :user')
    ->setParameter('user', $userArray)
    ->getQuery()
;

$results = $query->getResult();