Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Doctrine orm 使用条件/筛选器获取联接集合_Doctrine Orm - Fatal编程技术网

Doctrine orm 使用条件/筛选器获取联接集合

Doctrine orm 使用条件/筛选器获取联接集合,doctrine-orm,Doctrine Orm,我正在尝试加载实体并获取并加入另一个实体 $qb = $this->_em->createQueryBuilder(); $qb->addSelect('be, becs'); $qb->from('MeMyBundle:Entity', 'be'); $qb->leftJoin('be.associations', 'becs'); $qb->andWhere('becs.attribute=:attribute'); $qb->setParamete

我正在尝试加载实体并获取并加入另一个实体

$qb = $this->_em->createQueryBuilder();
$qb->addSelect('be, becs');
$qb->from('MeMyBundle:Entity', 'be');
$qb->leftJoin('be.associations', 'becs');
$qb->andWhere('becs.attribute=:attribute');
$qb->setParameter('attribute', $filterAttribute);
为了避免以后出现所有这些单一SQL结果,必须使用fetch连接

另一方面,如果不使用我的filterAttribute(在连接上设置where条件),将导致花费高昂的费用来水合太多我不需要的连接对象

但这导致了这样一个事实,即当不存在匹配的联接实体时,我的结果是空的。但我需要匹配的或空的集合


如何摆脱此陷阱?

尝试使用
leftJoin()
方法的第3和第4个参数

$qb = $this->_em->createQueryBuilder();
$qb->addSelect('be, becs');
$qb->from('MeMyBundle:Entity', 'be');
$qb->leftJoin('be.associations', 'becs', 'WITH', 'becs.attribute=:attribute');
$qb->setParameter('attribute', $filterAttribute);