Two things first. You need to create accessor methods for both classes. This means creating:
/**
* ...
*/
class TblUser
{
// ...
public function getRoles()
{
return $this->roles->toArray();
}
public function setRoles(Collection $roles)
{
foreach ($roles as $role) {
$this->addRole($role);
}
}
public function addRole(TblPrivilege $role)
{
if (!$this->roles->contains($role)) {
$this->roles->add($role);
$role->addUser($this);
}
}
public function removeRole(TblPrivilege $role)
{
if ($this->roles->contains($role)) {
$this->roles->removeElement($role);
$role->removeUser($this);
}
}
}
/**
* ...
*/
class TblPrivileges
{
// ...
public function getUsers()
{
return $this->users;
}
public function setUsers(Collection $users)
{
foreach ($users as $user) {
$this->addUser($user);
}
}
public function addUser(TblUser $user)
{
if (!$this->users->contains($user)) {
$this->users->add($user);
}
}
public function removeUser(TblUser $user)
{
if ($this->users->contains($user)) {
$this->users->removeElement($user);
}
}
}
For actually calling the $user->addRole() method, I would actually go for a Doctrine event subscriber, which would actually fetch the default role on persist (and thus, during registration). This is well documented on the Doctrine documentation.
To register an event subscriber, you should look at the Symfony documentation: