/** * @return array - having permissions list from the joining table */ public function getPermissionMappingList() { return $this->hasMany(RolePermission::className(), ['roleId' => 'id']); }
/** * @param BinderForm $binder * @return boolean */ public static function bindPermissions($binder) { $roleId = $binder->binderId; $permissions = $binder->bindedData; // Clear all existing mappings RolePermission::deleteByRoleId($roleId); // Create updated mappings if (isset($permissions) && count($permissions) > 0) { foreach ($permissions as $key => $value) { if (isset($value)) { $toSave = new RolePermission(); $toSave->roleId = $roleId; $toSave->permissionId = $value; $toSave->save(); } } } return true; }