With Doctrine 2, I have the following query:
/**
* @param Organization $organization
* @param User $user
* @return \Doctrine\ORM\QueryBuilder
*/
public function getFindByOrganizationQueryBuilder(Organization $organization, User $user)
{
$builder = $this
->createQueryBuilder('u')
->leftJoin('u.roles', 'r')
->where($this->createQueryBuilder('u')->expr()->orX(
$this->createQueryBuilder('u')->expr()->notIn('r.role', array('ROLE_SUPER_ADMIN', 'ROLE_ADMIN')),
$this->createQueryBuilder('u')->expr()->isNull('r')
))
;
return $builder;
}
This does not work as expected and returns users which have at least one role different than ROLE_ADMIN or ROLE_SUPER_ADMIN
Alternatively, I tried to replace the where clause by
->where('r.role <> 'ROLE_ADMIN')
->andWhere('r.role <> 'ROLE_SUPER_ADMIN')
Then it does not return users who have no roles.
How can I change the query so as it returns any user who has not either ROLE_ADMIN or ROLE_SUPER_ADMIN ?
Thanks a lot !