0

我已经使用 querybuilder 进行了查询。它看起来像:

//Create a Querybuilder
        $qb = $this->_em->createQueryBuilder();

        //Foreach entity, check if it's a join and leftjoin it.
        //If there's no join, make it the select
        foreach($config['entities'] as $name => $entity)
        {
            //add new alias(ses) to select statement
            $qb->addSelect($entity['alias']);

            if(!isset($entity['join'])){
                $qb->from($entity['path'], $entity['alias']);
            } else {
                $qb->leftJoin($entity['join'], $entity['alias']);
            }
        }
           ->orWhere(':test IS NULL')
       ->setParameter('test', 'User\Entity\Address');

    //Make the query
    $query = $qb->getQuery();

    //Return the result
    return $query->getResult();

我已经使用配置文件进行了选择并动态加入。所以人们可以自己加入。但是当我有(例如)用户和地址时。它只显示有地址的用户。不显示没有地址的用户。当我没有加入时,所有用户都会出现。有人对此有想法吗?我读了一些我必须设置 where 子句并执行以下操作的内容:

->orWhere(':test IS NULL')
           ->setParameter('test', 'User\Entity\Address');

它不起作用。我怎样才能加入并显示所有用户也没有地址?

格茨

4

1 回答 1

0

我的 where 子句有问题。它有一个“喜欢”,他想喜欢“街道”(来自地址)的东西。但是当用户没有地址时,他不能喜欢,所以他不会显示整个用户。

于 2013-05-02T12:15:16.707 回答