Doctrine QueryBuilder 多个不同的

Doctrine QueryBuilder multiple distinct

我想使用 doctrine ORM

DISTINCT 的结果限制在两列上

我的函数是这样的:

public function findFdvLinkedToPdv($pointVenteCodes){
    $queryBuilder = 
    $this->createQueryBuilder('r')
                ->leftJoin('r.forceVente', 'forceVente')
                ->leftJoin('r.pointVente', 'pointVente')
                ->leftJoin('r.signature', 'signature')
                ->leftJoin('signature.affaire', 'affaire')
                ->andWhere('pointVente.code IN (:pointvente_codes)')
                ->orderBy('forceVente.matricule', 'ASC')
                ->addOrderBy('pointVente.code', 'ASC')
                ->addOrderBy('affaire.code', 'ASC')
                ->addOrderBy('r.type', 'ASC')
                ->setParameters(array('pointvente_codes' => $pointVenteCodes,))
                ->select(array(
                        'forceVente.matricule AS forcevente_matricule',
                        'pointVente.code AS pointvente_code',
                        'affaire.code AS affaire_code',
                        'r.id AS id',
                        'r.profil AS profil',
                        'r.type AS type',
                        'forceVente.nom AS nom',
                        'forceVente.prenom AS prenom',
                        'forceVente.email AS email',
                        'r.deletedAt AS deletedAt'));
    return $queryBuilder->getQuery()->getArrayResult();
}

对于每个 forcevente.matricule 和每个 pointVente.code ,我有 2 到 6 行。我想为每一对 forcevente 获得一行。matricule/pointVente.code 我必须在两列上做一个 distinct,但是当我尝试时:

            ->select(array(
                    'DISTINCT forceVente.matricule AS forcevente_matricule',
                    'DISTINCT pointVente.code AS pointvente_code',
                    'affaire.code AS affaire_code', etc ...

我有一个学说错误...

[编辑] 我在执行过滤结果的请求后 PHP 执行此操作...

//BEGIN PATCH
$i=0;
$linkedForceVentes2 = array();
foreach ($linkedForceVentes as $item) {
    if (!isset($linkedForceVentes2[$item['pointvente_code']][$item['forcevente_matricule']])){
        $linkedForceVentes2[$item['pointvente_code']][$item['forcevente_matricule']] = $item;
    }else{
        unset($linkedForceVentes[$i]);
    }
    $i++;
}
//END PATCH

我终于用 groupBy 解决了它:

->groupBy('forcevente_matricule', 'pointvente_code', 'type' , 'affaire_code');

就在 select 语句之后。