I am trying to get the number of results where roles are not ROLE_ADMIN_USER. To do that I wrote following function in doctrine 2. But its not filtering the results. Any idea what it should be 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 !LIKE :role ')
->setParameter('query', '%' . $searchQuery . '%')
->setParameter('role','%ROLE_ADMIN_USER%')
->andwhere("u.adminApproved= 'Yes'")
->getQuery()
->getSingleScalarResult();
}
you can use 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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With