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:
2026-03-15 20:11:54 +01:00
parent 6d7e6f5f48
commit 6c910e7fcc

View File

@@ -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()
;