简体   繁体   中英

How to use orWhere in Doctrine | Return user who have ROLE_ADMIN and ROLE_USER

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM