Subquery in doctrine2 notIN Function

后端 未结 3 831
甜味超标
甜味超标 2020-11-30 06:09

I\'d like to select members who are not in specific service. I have 3 tables :

  • membre
  • service
  • membre_service<
3条回答
  •  日久生厌
    2020-11-30 06:27

    Actually if you are using the Symfony2 repository class you could also do the following:

    $in = $this->getEntityManager()->getRepository('Custom:MembreService')
        ->createQueryBuilder('ms')
        ->select('identity(ms.m)')
        ->where(ms.id != ?1);
    
    $q = $this->createQueryBuilder('m')
        ->where($q->expr()->notIn('m.id', $in->getDQL()))
        ->setParameter(1, $service);
    
    return $q->getQuery()->execute();
    

提交回复
热议问题