我正在尝试获取角色不是ROLE_ADMIN_USER
的结果数。为此,我在学说2中编写了以下函数。但它没有过滤结果。知道应该是什么样的吗?
public function getApprovedUserSearchNumber($searchQuery)
{
return $this->getEntityManager()->createQueryBuilder('u')
->select('COUNT(u)')
->from('AppBundle:User', 'u')
->andwhere('u.username LIKE :query ')
->andwhere('u.roles !LIKE :role ')
->setParameter('query', '%' . $searchQuery . '%')
->setParameter('role','%ROLE_ADMIN_USER%')
->andwhere("u.adminApproved= 'Yes'")
->getQuery()
->getSingleScalarResult();
}
答案 0 :(得分:2)
您可以使用 NOT LIKE
public function getApprovedUserSearchNumber($searchQuery)
{
return $this->getEntityManager()->createQueryBuilder('u')
->select('COUNT(u)')
->from('AppBundle:User', 'u')
->andwhere('u.username LIKE :query ')
->andwhere('u.roles NOT LIKE :role ')
->setParameter('query', '%' . $searchQuery . '%')
->setParameter('role','%ROLE_ADMIN_USER%')
->andwhere("u.adminApproved= 'Yes'")
->getQuery()
->getSingleScalarResult();
}