M
M
Max2019-11-02 20:31:34
symfony
Max, 2019-11-02 20:31:34

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

1 answer(s)
M
Max, 2019-11-03
@maximrabotaet

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 question

Ask a Question

731 491 924 answers to any question