<?php
use ActiveRecord\Model;
class UserRole extends Model {
    static $primary_key = "user_id";
	 static $belongs_to = array(
     array('user'),
             array('role')
   );
   
   static function NewInsert($data){
	   $sql ="
	   DECLARE @USERID INT = ?
	   DECLARE @ROLEID INT = ?
	   DELETE FROM [dbo].[user_roles] WHERE [user_id] = @USERID;
INSERT INTO [dbo].[user_roles]
           ([user_id]
           ,[role_id])
     VALUES
           (@USERID
           ,@ROLEID)";
		   $pdo = self::connection()->connection;
			$Exe = $pdo->prepare($sql);
			return $Exe->execute(array($data['user_id'],$data['role_id']));
	   
   }
}