GraphAware\Neo4j\OGM\Tests\Integration\Model\User::addRole PHP Method

addRole() public method

public addRole ( SecurityRole $securityRole )
$securityRole SecurityRole
    public function addRole(SecurityRole $securityRole)
    {
        $this->roles->add($securityRole);
        $securityRole->getUsers()->add($this);
    }

Usage Example

 private function init()
 {
     // Setup initial graph
     $this->clearDb();
     $user = new User('ikwattro');
     $role = new SecurityRole('view_pages');
     foreach (['wood', 'stone', 'water', 'sun', 'coat'] as $res) {
         $resource = new ResourceModel($res);
         $this->em->persist($resource);
     }
     $user->addRole($role);
     $this->em->persist($user);
     $this->em->flush();
     $this->em->clear();
 }