I gave my user the $roleId role. I tested this code:
Output is this:
Why does it print that? The only expected result is $a. What am I doing wrong? I think I'm using the correct relation names.
Why doesn't isRelated work and findRelated does? And why does it only work from the Role repository? This looks like a bug...
Is there a builtin function to check for roles?
Thanks!
PHP Code:
$user = $this->getUser();
$userId = $user->id;
$userRepository = $this->getEntityManager()->getRepository('User');
$roleId = '5ec00777b9d015264';
$role = $this->getEntityManager()->getEntity('Role', $roleId);
$roleRepository = $this->getEntityManager()->getRepository('Role');
$a = count($roleRepository->findRelated($role, 'users')-> getDataList());
$b = $roleRepository->isRelated($role, 'users', $userId);
$c = count($userRepository->findRelated($user, 'roles')-> getDataList());
$d = $userRepository->isRelated($user, 'roles', $roleId);
$get = $user->get('roles');
echo "get=".json_encode($get)." a=$a b=".json_encode($b)." c=$c d=".json_encode($d);
Code:
get={} a=1 b=false c=0 d=false
Why does it print that? The only expected result is $a. What am I doing wrong? I think I'm using the correct relation names.
Why doesn't isRelated work and findRelated does? And why does it only work from the Role repository? This looks like a bug...
Is there a builtin function to check for roles?
Thanks!
Comment