I have a User entity and a HistoryAccess entity that binds two User instances as follows: a user specified in it as "allowed" can get a user specified as "owner".
I am trying to make a query that will receive the data of all users available to the current user. Query code:
$user = $security->getUser();
$userId = $user->getId()->toRfc4122();
return $entityManager->createQueryBuilder()
->from('App\Entity\User', 'u')
->join('u.ownerHistoryAccesses', 'ha')
->join('ha.allowed', 'a')
->where('a.id = :currentUserId')
->setParameter('currentUserId', $userId)
->select('u, ha, a.id')
->getQuery()
->getArrayResult();
But this query does not return anything
If I delete the andWhere and setParameter lines, the result is the expected dataset, with a.id being the same identifier as the $userId value. Why doesn’t the request with the andWhere and setParameter return anything?
The problem was not in the query, but in the ID format. The database did not store RFC4122, but a binary format. So I had to replace toRfc4122()
with toBinary()