1

I want to return user who have ROLE_ADMIN and ROLE_USER

I have did this in repository :

return $this->createQueryBuilder('u')
        ->where('u.roles IN (:val)')
        ->setParameter('val','["ROLE_ADMIN","ROLE_USER"]')
        ->getQuery()
        ->getResult();

But nothing is returned... How to solve this probleme?

ps: I have a user with ROLES : ROLE_ADMIN and ROLE_USER

Imanali Mamadiev
  • 2,604
  • 2
  • 15
  • 23
Khalil
  • 288
  • 3
  • 16

1 Answers1

1

To use orWhere in Doctrine 2:

return $this->createQueryBuilder('u')
        ->where('u.roles LIKE :val')
        ->setParameter('val','%ROLE_ADMIN%')
        ->orWhere('u.roles LIKE :val2')
        ->setParameter('val2', '%ROLE_USER%')
        ->getQuery()
        ->getResult();

Also You can use like this:

return $this->createQueryBuilder('u')
        ->where('u.roles LIKE :val')
        ->orWhere('u.roles LIKE :val2')
        ->setParameters(array('val2' => '%ROLE_USER%', 'val' => '%ROLE_ADMIN%'))
        ->getQuery()
        ->getResult();
Imanali Mamadiev
  • 2,604
  • 2
  • 15
  • 23
  • Thanks Its work, but how when i want more Roles not only ROLE_ADMIN? For example u.roles Like %ROLE_ADMIN% or %ROLE_USER% => How to do this please? – Khalil Mar 23 '19 at 12:46