src/Synapse/User/UserRolePivotMapper.php
public function addRoleForUser($userId, $roleName)
    {
        $roleIdExpression = new Expression(
            '(SELECT `id` from `user_roles` WHERE `name` = ?)',
            $roleName
        );

        $query = $this->getSqlObject()
            ->insert()
            ->values([
                'user_id' => $userId,
                'role_id' => $roleIdExpression,
            ]);

        $this->execute($query);
    }
public function addRoleForUser($userId, $roleName)
    {
        $roleIdExpression = new Expression(
            '(SELECT `id` from `user_roles` WHERE `name` = ?)',
            $roleName
        );

        $query = $this->getSqlObject()
            ->insert()
            ->values([
                'user_id' => $userId,
                'role_id' => $roleIdExpression,
            ]);

        $this->execute($query);
    }
public function addRoleForUser ( $ userId , $ roleName ) { $ roleIdExpression = new Expression ( '(SELECT `id` from `user_roles` WHERE `name` = ?)' , $ roleName ) ; $ query = $ this -> getSqlObject ( ) -> insert ( ) -> values ( [ 'user_id' => $ userId , 'role_id' => $ roleIdExpression , ] ) ; $ this -> execute ( $ query ) ; }
Add a given role to the given user id

@param int    $userId
@param string $roleName
Add a given role to the given user id