fix : use native SQL for JSON roles query in PostgreSQL
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,9 +23,17 @@ class UserRepository extends ServiceEntityRepository
|
||||
*/
|
||||
public function findByRole(string $role): array
|
||||
{
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
$sql = 'SELECT id FROM "user" WHERE roles::text LIKE :role';
|
||||
$ids = $conn->executeQuery($sql, ['role' => '%"'.$role.'"%'])->fetchFirstColumn();
|
||||
|
||||
if ([] === $ids) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->createQueryBuilder('u')
|
||||
->where('u.roles LIKE :role')
|
||||
->setParameter('role', '%"'.$role.'"%')
|
||||
->where('u.id IN (:ids)')
|
||||
->setParameter('ids', $ids)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user