doctrine sonata query builder嵌套查询

时间:2018-06-06 06:15:11

标签: doctrine-orm query-builder sonata

我正在尝试在管理类中编辑奏鸣曲createQuery,这是我的函数

public function createQuery($context = 'list')
{
    $container = $this->getConfigurationPool()->getContainer();
    $query = parent::createQuery($context);
    if ($container->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN') !== false) {
        /**
         * @var User $user
         */
        $user = $container->get('security.token_storage')->getToken()->getUser();
        $em = $container->get('doctrine.orm.entity_manager');
        /** @var QueryBuilder $qb1 */
        $qb1 = $em->createQueryBuilder();
        $select = $qb1->select('u.id')
            ->from('ImmoApplicationBundle:Prospect', 'p')
            ->innerJoin('p.users', 'u')
            ->where('p.id = :prospect_id')
            ->getQuery();
        $query->andWhere(
            $query->expr()->in(':user', $select->getDQL())

        );
        $query->setParameter('user', 1);
        $query->setParameter('prospect_id', $query->getRootAlias()[0] . '.id');
    }
    return $query;
}

但它不起作用,参数:prospect_id将被转换为字符串'o.id'

0 个答案:

没有答案