Answer the question
In order to leave comments, you need to log in
How to pull users in symfony 3.4 who don't have specific roles?
Hello!
I use FOSUserBundle for users. In essence, there is a roles field of type array whose multiple values are stored in the database. I need to select from the database all users who do not have the "ROLE_ADMIN" role, how to do this using the doctrine? And where can I read about such a selection of non-standard database types that are in the doctrine?
Answer the question
In order to leave comments, you need to log in
Like this:
/**
* @param string $role
*
* @return array
*/
public function findWithoutRole($role)
{
$qb = $this->_em->createQueryBuilder();
$qb->select('u')
->from($this->_entityName, 'u')
->where('u.roles NOT LIKE :roles')
->setParameter('roles', '%"' . $role . '"%');
return $qb->getQuery()->getResult();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question