# DbManager

> DbManager represents an authorization manager that stores authorization information in database.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [rbac](/docs/api/yii/rbac/index.md) › DbManager

| class | `yii\rbac\DbManager` |
| --- | --- |
| Extends | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/rbac/DbManager.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/rbac/DbManager.php#L46) |

DbManager represents an authorization manager that stores authorization information in database.

The database connection is specified by [`$db`](/docs/api/yii/rbac/dbmanager/index.md#property-db). The database schema could be initialized by applying migration:

```
yii migrate --migrationPath=@yii/rbac/migrations/
```

If you don't want to use migration and need SQL instead, files for all databases are in migrations directory.

You may change the names of the tables used to store the authorization and rule data by setting [`$itemTable`](/docs/api/yii/rbac/dbmanager/index.md#property-itemTable),
[`$itemChildTable`](/docs/api/yii/rbac/dbmanager/index.md#property-itemChildTable), [`$assignmentTable`](/docs/api/yii/rbac/dbmanager/index.md#property-assignmentTable) and [`$ruleTable`](/docs/api/yii/rbac/dbmanager/index.md#property-ruleTable).

For more details and usage information on DbManager, see the [guide article on security authorization](/docs/guide/security-authorization/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$assignmentTable`](#property-assignmentTable) | `string` | The name of the table storing authorization item assignments. Default: `'{{%auth_assignment}}'`. | `DbManager` |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`$cache`](#property-cache) | [`yii\caching\CacheInterface`](/docs/api/yii/caching/cacheinterface/index.md)`\|array\|string\|null` | The cache used to improve RBAC performance. Default: `null`. Available since 2.0.3. | `DbManager` |
| <span id="property-cacheKey"></span>`$cacheKey` | `string` | The key used to store RBAC data in cache Default: `'rbac'`. Available since 2.0.3. | `DbManager` |
| [`$db`](#property-db) | [`yii\db\Connection`](/docs/api/yii/db/connection/index.md)`\|array\|string` | The DB connection object or the application component ID of the DB connection. Default: `'db'`. | `DbManager` |
| <span id="property-defaultRoleInstances"></span>[`$defaultRoleInstances`](/docs/api/yii/rbac/basemanager/index.md#property-defaultRoleInstances) read-only | [`Role`](/docs/api/yii/rbac/role/index.md)`[]` | Default roles. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| [`$itemChildTable`](#property-itemChildTable) | `string` | The name of the table storing authorization item hierarchy. Default: `'{{%auth_item_child}}'`. | `DbManager` |
| [`$itemTable`](#property-itemTable) | `string` | The name of the table storing authorization items. Default: `'{{%auth_item}}'`. | `DbManager` |
| <span id="property-permissions"></span>[`$permissions`](/docs/api/yii/rbac/basemanager/index.md#property-permissions) read-only | [`Permission`](/docs/api/yii/rbac/permission/index.md)`[]` | All permissions in the system. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| <span id="property-roles"></span>[`$roles`](/docs/api/yii/rbac/basemanager/index.md#property-roles) read-only | [`Role`](/docs/api/yii/rbac/role/index.md)`[]` | All roles in the system. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| <span id="property-rolesCacheSuffix"></span>`$rolesCacheSuffix` | `string` | The key used to store user RBAC roles in cache Default: `'roles'`. Available since 2.0.48. | `DbManager` |
| [`$ruleTable`](#property-ruleTable) | `string` | The name of the table storing rules. Default: `'{{%auth_rule}}'`. | `DbManager` |
| <span id="property-checkAccessAssignments"></span>`$checkAccessAssignments` protected | `array` | User assignments (user id => Assignment[]) Default: `[]`. | `DbManager` |
| <span id="property-defaultRoles"></span>[`$defaultRoles`](/docs/api/yii/rbac/basemanager/index.md#property-defaultRoles) protected | `array` | A list of role names that are assigned to every user automatically without calling [`assign()`](/docs/api/yii/rbac/managerinterface/index.md#method-assign). Default: `[]`. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| <span id="property-items"></span>`$items` protected | [`Item`](/docs/api/yii/rbac/item/index.md)`[]\|null` | All auth items (name => Item) Default: `null`. | `DbManager` |
| <span id="property-parents"></span>`$parents` protected | `array\|null` | Auth item parent-child relationships (childName => list of parents) Default: `null`. | `DbManager` |
| <span id="property-rules"></span>`$rules` protected | [`Rule`](/docs/api/yii/rbac/rule/index.md)`[]\|null` | All auth rules (name => Rule) Default: `null`. | `DbManager` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-add"></span>[`add()`](/docs/api/yii/rbac/basemanager/index.md#method-add) | Adds a role, permission or rule to the RBAC system. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| [`addChild()`](#method-addChild) | Adds an item as a child of another item. | `DbManager` |
| [`assign()`](#method-assign) | Assigns a role to a user. | `DbManager` |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`canAddChild()`](#method-canAddChild) | Checks the possibility of adding a child to parent. | `DbManager` |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`checkAccess()`](#method-checkAccess) |  | `DbManager` |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-createPermission"></span>[`createPermission()`](/docs/api/yii/rbac/basemanager/index.md#method-createPermission) | Creates a new Permission object. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| <span id="method-createRole"></span>[`createRole()`](/docs/api/yii/rbac/basemanager/index.md#method-createRole) | Creates a new Role object. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`getAssignment()`](#method-getAssignment) | Returns the assignment information regarding a role and a user. | `DbManager` |
| [`getAssignments()`](#method-getAssignments) | Returns all role assignment information for the specified user. | `DbManager` |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`getChildren()`](#method-getChildren) | Returns the child permissions and/or roles. | `DbManager` |
| [`getChildRoles()`](#method-getChildRoles) | Returns child roles of the role specified. Depth isn't limited. | `DbManager` |
| <span id="method-getDefaultRoleInstances"></span>[`getDefaultRoleInstances()`](/docs/api/yii/rbac/basemanager/index.md#method-getDefaultRoleInstances) | Returns defaultRoles as array of Role objects. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| <span id="method-getDefaultRoles"></span>[`getDefaultRoles()`](/docs/api/yii/rbac/basemanager/index.md#method-getDefaultRoles) | Get default roles | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| <span id="method-getPermission"></span>[`getPermission()`](/docs/api/yii/rbac/basemanager/index.md#method-getPermission) | Returns the named permission. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| <span id="method-getPermissions"></span>[`getPermissions()`](/docs/api/yii/rbac/basemanager/index.md#method-getPermissions) | Returns all permissions in the system. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| [`getPermissionsByRole()`](#method-getPermissionsByRole) | Returns all permissions that the specified role represents. | `DbManager` |
| [`getPermissionsByUser()`](#method-getPermissionsByUser) | Returns all permissions that the user has. | `DbManager` |
| <span id="method-getRole"></span>[`getRole()`](/docs/api/yii/rbac/basemanager/index.md#method-getRole) | Returns the named role. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| <span id="method-getRoles"></span>[`getRoles()`](/docs/api/yii/rbac/basemanager/index.md#method-getRoles) | Returns all roles in the system. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| [`getRolesByUser()`](#method-getRolesByUser) | The roles returned by this method include the roles assigned via [`$defaultRoles`](/docs/api/yii/rbac/basemanager/index.md#property-defaultRoles). | `DbManager` |
| [`getRule()`](#method-getRule) | Returns the rule of the specified name. | `DbManager` |
| [`getRules()`](#method-getRules) | Returns all rules available in the system. | `DbManager` |
| [`getUserIdsByRole()`](#method-getUserIdsByRole) | Returns all role assignment information for the specified role. | `DbManager` |
| [`hasChild()`](#method-hasChild) | Returns a value indicating whether the child already exists for the parent. | `DbManager` |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`init()`](#method-init) | Initializes the application component. | `DbManager` |
| [`invalidateCache()`](#method-invalidateCache) |  | `DbManager` |
| [`loadFromCache()`](#method-loadFromCache) |  | `DbManager` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-remove"></span>[`remove()`](/docs/api/yii/rbac/basemanager/index.md#method-remove) | Removes a role, permission or rule from the RBAC system. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| [`removeAll()`](#method-removeAll) | Removes all authorization data, including roles, permissions, rules, and assignments. | `DbManager` |
| [`removeAllAssignments()`](#method-removeAllAssignments) | Removes all role assignments. | `DbManager` |
| [`removeAllPermissions()`](#method-removeAllPermissions) | Removes all permissions. | `DbManager` |
| [`removeAllRoles()`](#method-removeAllRoles) | Removes all roles. | `DbManager` |
| [`removeAllRules()`](#method-removeAllRules) | Removes all rules. | `DbManager` |
| [`removeChild()`](#method-removeChild) | Removes a child from its parent. | `DbManager` |
| [`removeChildren()`](#method-removeChildren) | Removed all children form their parent. | `DbManager` |
| [`revoke()`](#method-revoke) | Revokes a role from a user. | `DbManager` |
| [`revokeAll()`](#method-revokeAll) | Revokes all roles from a user. | `DbManager` |
| <span id="method-setDefaultRoles"></span>[`setDefaultRoles()`](/docs/api/yii/rbac/basemanager/index.md#method-setDefaultRoles) | Set default roles | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-update"></span>[`update()`](/docs/api/yii/rbac/basemanager/index.md#method-update) | Updates the specified role, permission or rule in the system. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| [`addItem()`](#method-addItem) protected | Adds an auth item to the RBAC system. | `DbManager` |
| [`addRule()`](#method-addRule) protected | Adds a rule to the RBAC system. | `DbManager` |
| [`checkAccessFromCache()`](#method-checkAccessFromCache) protected | Performs access check for the specified user based on the data loaded from cache. | `DbManager` |
| [`checkAccessRecursive()`](#method-checkAccessRecursive) protected | Performs access check for the specified user. | `DbManager` |
| [`detectLoop()`](#method-detectLoop) protected | Checks whether there is a loop in the authorization item hierarchy. | `DbManager` |
| <span id="method-executeRule"></span>[`executeRule()`](/docs/api/yii/rbac/basemanager/index.md#method-executeRule) protected | Executes the rule associated with the specified auth item. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| [`getChildrenList()`](#method-getChildrenList) protected | Returns the children for every parent. | `DbManager` |
| [`getChildrenRecursive()`](#method-getChildrenRecursive) protected | Recursively finds all children and grand children of the specified item. | `DbManager` |
| [`getDirectPermissionsByUser()`](#method-getDirectPermissionsByUser) protected | Returns all permissions that are directly assigned to user. | `DbManager` |
| [`getInheritedPermissionsByUser()`](#method-getInheritedPermissionsByUser) protected | Returns all permissions that the user inherits from the roles assigned to him. | `DbManager` |
| [`getItem()`](#method-getItem) protected | Returns the named auth item. | `DbManager` |
| [`getItems()`](#method-getItems) protected | Returns the items of the specified type. | `DbManager` |
| <span id="method-hasNoAssignments"></span>[`hasNoAssignments()`](/docs/api/yii/rbac/basemanager/index.md#method-hasNoAssignments) protected | Checks whether array of $assignments is empty and [`$defaultRoles`](/docs/api/yii/rbac/basemanager/index.md#property-defaultRoles) property is empty as well. | [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md) |
| [`isEmptyUserId()`](#method-isEmptyUserId) protected | Check whether $userId is empty. | `DbManager` |
| [`populateItem()`](#method-populateItem) protected | Populates an auth item with the data fetched from database. | `DbManager` |
| [`removeAllItems()`](#method-removeAllItems) protected | Removes all auth items of the specified type. | `DbManager` |
| [`removeAllItemsManualCascade()`](#method-removeAllItemsManualCascade) protected | Removes all auth items of the given type without relying on FK enforcement. | `DbManager` |
| [`removeAllItemsSoftCascade()`](#method-removeAllItemsSoftCascade) protected | Removes all auth items of the given type when FKs cascade for every direction except `auth_item_child.child`. | `DbManager` |
| [`removeAllRulesManualCascade()`](#method-removeAllRulesManualCascade) protected | Removes every auth rule without relying on FK enforcement. | `DbManager` |
| [`removeItem()`](#method-removeItem) protected | Removes an auth item from the RBAC system. | `DbManager` |
| [`removeItemManualCascade()`](#method-removeItemManualCascade) protected | Removes an item without relying on FK enforcement. | `DbManager` |
| [`removeItemSoftCascade()`](#method-removeItemSoftCascade) protected | Removes an item when FKs cascade for every direction except `auth_item_child.child`. | `DbManager` |
| [`removeRule()`](#method-removeRule) protected | Removes a rule from the RBAC system. | `DbManager` |
| [`removeRuleManualCascade()`](#method-removeRuleManualCascade) protected | Removes a rule without relying on FK enforcement. | `DbManager` |
| [`requiresSoftCascade()`](#method-requiresSoftCascade) protected | Returns whether the driver requires a partial PHP-level cleanup of `auth_item_child` rows whose `child` column references the affected item. | `DbManager` |
| [`supportsCascadeUpdate()`](#method-supportsCascadeUpdate) protected | Returns whether the database performs cascade updates and deletes automatically (for example, via FK `ON UPDATE CASCADE` / `ON DELETE CASCADE`). | `DbManager` |
| [`updateItem()`](#method-updateItem) protected | Updates an auth item in the RBAC system. | `DbManager` |
| [`updateItemManualCascade()`](#method-updateItemManualCascade) protected | Renames an item without relying on FK enforcement. | `DbManager` |
| [`updateItemSoftCascade()`](#method-updateItemSoftCascade) protected | Renames an item when FKs cascade for every direction except `auth_item_child.child` (MSSQL multi-path). | `DbManager` |
| [`updateRule()`](#method-updateRule) protected | Updates a rule to the RBAC system. | `DbManager` |
| [`updateRuleManualCascade()`](#method-updateRuleManualCascade) protected | Renames a rule without relying on FK enforcement. | `DbManager` |

## Property details

### $assignmentTable <span id="property-assignmentTable"></span>

```php
public string $assignmentTable = '{{%auth_assignment}}'
```

The name of the table storing authorization item assignments.

Defaults to "auth_assignment".

### $cache <span id="property-cache"></span>

```php
public yii\caching\CacheInterface|array|string|null $cache = null
```

The cache used to improve RBAC performance.

This can be one of the following:

- an application component ID (e.g. `cache`)
- a configuration array
- a [`Cache`](/docs/api/yii/caching/cache/index.md) object

When this is not set, it means caching is not enabled.

Note that by enabling RBAC cache, all auth items, rules and auth item parent-child relationships will
be cached and loaded into memory. This will improve the performance of RBAC permission check. However,
it does require extra memory and as a result may not be appropriate if your RBAC system contains too many
auth items. You should seek other RBAC implementations (e.g. RBAC based on Redis storage) in this case.

Also note that if you modify RBAC items, rules or parent-child relationships from outside of this component,
you have to manually call [`invalidateCache()`](/docs/api/yii/rbac/dbmanager/index.md#method-invalidateCache) to ensure data consistency.

**Since**

2.0.3

### $db <span id="property-db"></span>

```php
public yii\db\Connection|array|string $db = 'db'
```

The DB connection object or the application component ID of the DB connection.

After the DbManager object is created, if you want to change this property, you should only assign it
with a DB connection object.
Starting from version 2.0.2, this can also be a configuration array for creating the object.

### $itemChildTable <span id="property-itemChildTable"></span>

```php
public string $itemChildTable = '{{%auth_item_child}}'
```

The name of the table storing authorization item hierarchy.

Defaults to "auth_item_child".

### $itemTable <span id="property-itemTable"></span>

```php
public string $itemTable = '{{%auth_item}}'
```

The name of the table storing authorization items.

Defaults to "auth_item".

### $ruleTable <span id="property-ruleTable"></span>

```php
public string $ruleTable = '{{%auth_rule}}'
```

The name of the table storing rules.

Defaults to "auth_rule".

## Method details

### addChild() <span id="method-addChild"></span>

```php
public function addChild(mixed $parent, mixed $child): bool
```

Adds an item as a child of another item.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$parent` | `mixed` |  |
| `$child` | `mixed` |  |

**Returns**

`bool`: Whether the child successfully added

**Throws**

- [`yii\base\Exception`](/docs/api/yii/base/exception/index.md): if the parent-child relationship already exists or if a loop has been detected.

### assign() <span id="method-assign"></span>

```php
public function assign(mixed $role, mixed $userId): yii\rbac\Assignment
```

Assigns a role to a user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$role` | `mixed` |  |
| `$userId` | `mixed` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

[`Assignment`](/docs/api/yii/rbac/assignment/index.md): The role assignment information.

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if the role has already been assigned to the user

### canAddChild() <span id="method-canAddChild"></span>

```php
public function canAddChild(mixed $parent, mixed $child): bool
```

Checks the possibility of adding a child to parent.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$parent` | `mixed` | The parent item |
| `$child` | `mixed` | The child item to be added to the hierarchy |

**Returns**

`bool`: Possibility of adding

**Since**

2.0.8

### checkAccess() <span id="method-checkAccess"></span>

```php
public function checkAccess(mixed $userId, mixed $permissionName, mixed $params = [])
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `mixed` |  |
| `$permissionName` | `mixed` |  |
| `$params` | `mixed` |  |

### getAssignment() <span id="method-getAssignment"></span>

```php
public function getAssignment(mixed $roleName, mixed $userId): yii\rbac\Assignment|null
```

Returns the assignment information regarding a role and a user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$roleName` | `mixed` | The role name |
| `$userId` | `mixed` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

[`Assignment`](/docs/api/yii/rbac/assignment/index.md)`|null`: The assignment information. Null is returned if the role is not assigned to the user.

### getAssignments() <span id="method-getAssignments"></span>

```php
public function getAssignments(mixed $userId): yii\rbac\Assignment[]
```

Returns all role assignment information for the specified user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `mixed` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

[`Assignment`](/docs/api/yii/rbac/assignment/index.md)`[]`: The assignments indexed by role names. An empty array will be returned if there is no role assigned to the user.

### getChildren() <span id="method-getChildren"></span>

```php
public function getChildren(mixed $name): yii\rbac\Item[]
```

Returns the child permissions and/or roles.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The parent name |

**Returns**

[`Item`](/docs/api/yii/rbac/item/index.md)`[]`: The child permissions and/or roles

### getChildRoles() <span id="method-getChildRoles"></span>

```php
public function getChildRoles(mixed $roleName): yii\rbac\Role[]
```

Returns child roles of the role specified. Depth isn't limited.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$roleName` | `mixed` | Name of the role to file child roles for |

**Returns**

[`Role`](/docs/api/yii/rbac/role/index.md)`[]`: Child roles. The array is indexed by the role names. First element is an instance of the parent Role itself.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if Role was not found that are getting by $roleName

**Since**

2.0.10

### getPermissionsByRole() <span id="method-getPermissionsByRole"></span>

```php
public function getPermissionsByRole(mixed $roleName): yii\rbac\Permission[]
```

Returns all permissions that the specified role represents.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$roleName` | `mixed` | The role name |

**Returns**

[`Permission`](/docs/api/yii/rbac/permission/index.md)`[]`: All permissions that the role represents. The array is indexed by the permission names.

### getPermissionsByUser() <span id="method-getPermissionsByUser"></span>

```php
public function getPermissionsByUser(mixed $userId): yii\rbac\Permission[]
```

Returns all permissions that the user has.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `mixed` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

[`Permission`](/docs/api/yii/rbac/permission/index.md)`[]`: All permissions that the user has. The array is indexed by the permission names.

### getRolesByUser() <span id="method-getRolesByUser"></span>

```php
public function getRolesByUser(mixed $userId): mixed
```

The roles returned by this method include the roles assigned via [`$defaultRoles`](/docs/api/yii/rbac/basemanager/index.md#property-defaultRoles).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `mixed` |  |

**Returns**

`mixed`

### getRule() <span id="method-getRule"></span>

```php
public function getRule(mixed $name): yii\rbac\Rule|null
```

Returns the rule of the specified name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The rule name |

**Returns**

[`Rule`](/docs/api/yii/rbac/rule/index.md)`|null`: The rule object, or null if the specified name does not correspond to a rule.

### getRules() <span id="method-getRules"></span>

```php
public function getRules(): yii\rbac\Rule[]
```

Returns all rules available in the system.

**Returns**

[`Rule`](/docs/api/yii/rbac/rule/index.md)`[]`: The rules indexed by the rule names

### getUserIdsByRole() <span id="method-getUserIdsByRole"></span>

```php
public function getUserIdsByRole(string $roleName): string[]
```

Returns all role assignment information for the specified role.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$roleName` | `string` |  |

**Returns**

`string[]`: The ids. An empty array will be returned if role is not assigned to any user.

**Since**

2.0.7

### hasChild() <span id="method-hasChild"></span>

```php
public function hasChild(mixed $parent, mixed $child): bool
```

Returns a value indicating whether the child already exists for the parent.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$parent` | `mixed` |  |
| `$child` | `mixed` |  |

**Returns**

`bool`: Whether `$child` is already a child of `$parent`

### init() <span id="method-init"></span>

```php
public function init(): mixed
```

Initializes the application component.

This method overrides the parent implementation by establishing the database connection.

**Returns**

`mixed`

### invalidateCache() <span id="method-invalidateCache"></span>

```php
public function invalidateCache(): mixed
```

**Returns**

`mixed`

### loadFromCache() <span id="method-loadFromCache"></span>

```php
public function loadFromCache(): mixed
```

**Returns**

`mixed`

### removeAll() <span id="method-removeAll"></span>

```php
public function removeAll(): mixed
```

Removes all authorization data, including roles, permissions, rules, and assignments.

**Returns**

`mixed`

### removeAllAssignments() <span id="method-removeAllAssignments"></span>

```php
public function removeAllAssignments(): mixed
```

Removes all role assignments.

**Returns**

`mixed`

### removeAllPermissions() <span id="method-removeAllPermissions"></span>

```php
public function removeAllPermissions(): mixed
```

Removes all permissions.

All parent child relations will be adjusted accordingly.

**Returns**

`mixed`

### removeAllRoles() <span id="method-removeAllRoles"></span>

```php
public function removeAllRoles(): mixed
```

Removes all roles.

All parent child relations will be adjusted accordingly.

**Returns**

`mixed`

### removeAllRules() <span id="method-removeAllRules"></span>

```php
public function removeAllRules(): mixed
```

Removes all rules.

All roles and permissions which have rules will be adjusted accordingly.

**Returns**

`mixed`

### removeChild() <span id="method-removeChild"></span>

```php
public function removeChild(mixed $parent, mixed $child): bool
```

Removes a child from its parent.

Note, the child item is not deleted. Only the parent-child relationship is removed.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$parent` | `mixed` |  |
| `$child` | `mixed` |  |

**Returns**

`bool`: Whether the removal is successful

### removeChildren() <span id="method-removeChildren"></span>

```php
public function removeChildren(mixed $parent): bool
```

Removed all children form their parent.

Note, the children items are not deleted. Only the parent-child relationships are removed.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$parent` | `mixed` |  |

**Returns**

`bool`: Whether the removal is successful

### revoke() <span id="method-revoke"></span>

```php
public function revoke(mixed $role, mixed $userId): bool
```

Revokes a role from a user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$role` | `mixed` |  |
| `$userId` | `mixed` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

`bool`: Whether the revoking is successful

### revokeAll() <span id="method-revokeAll"></span>

```php
public function revokeAll(mixed $userId): bool
```

Revokes all roles from a user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `mixed` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

`bool`: Whether the revoking is successful

### addItem() <span id="method-addItem"></span>

```php
protected function addItem(mixed $item): bool
```

Adds an auth item to the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$item` | `mixed` | The item to add |

**Returns**

`bool`: Whether the auth item is successfully added to the system

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the role or permission is not unique)

### addRule() <span id="method-addRule"></span>

```php
protected function addRule(mixed $rule): bool
```

Adds a rule to the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rule` | `mixed` | The rule to add |

**Returns**

`bool`: Whether the rule is successfully added to the system

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the rule is not unique)

### checkAccessFromCache() <span id="method-checkAccessFromCache"></span>

```php
protected function checkAccessFromCache(string|int $user, string $itemName, array $params, yii\rbac\Assignment[] $assignments): bool
```

Performs access check for the specified user based on the data loaded from cache.

This method is internally called by [`checkAccess()`](/docs/api/yii/rbac/dbmanager/index.md#method-checkAccess) when [`$cache`](/docs/api/yii/rbac/dbmanager/index.md#property-cache) is enabled.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$user` | `string\|int` | The user ID. This should can be either an integer or a string representing the unique identifier of a user. See [`User::$id`](/docs/api/yii/web/user/index.md#property-id). |
| `$itemName` | `string` | The name of the operation that need access check |
| `$params` | `array` | Name-value pairs that would be passed to rules associated with the tasks and roles assigned to the user. A param with name 'user' is added to this array, which holds the value of `$userId`. |
| `$assignments` | [`Assignment`](/docs/api/yii/rbac/assignment/index.md)`[]` | The assignments to the specified user |

**Returns**

`bool`: Whether the operations can be performed by the user.

**Since**

2.0.3

### checkAccessRecursive() <span id="method-checkAccessRecursive"></span>

```php
protected function checkAccessRecursive(string|int $user, string $itemName, array $params, yii\rbac\Assignment[] $assignments): bool
```

Performs access check for the specified user.

This method is internally called by [`checkAccess()`](/docs/api/yii/rbac/dbmanager/index.md#method-checkAccess).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$user` | `string\|int` | The user ID. This should can be either an integer or a string representing the unique identifier of a user. See [`User::$id`](/docs/api/yii/web/user/index.md#property-id). |
| `$itemName` | `string` | The name of the operation that need access check |
| `$params` | `array` | Name-value pairs that would be passed to rules associated with the tasks and roles assigned to the user. A param with name 'user' is added to this array, which holds the value of `$userId`. |
| `$assignments` | [`Assignment`](/docs/api/yii/rbac/assignment/index.md)`[]` | The assignments to the specified user |

**Returns**

`bool`: Whether the operations can be performed by the user.

### detectLoop() <span id="method-detectLoop"></span>

```php
protected function detectLoop(yii\rbac\Item $parent, yii\rbac\Item $child): bool
```

Checks whether there is a loop in the authorization item hierarchy.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$parent` | [`Item`](/docs/api/yii/rbac/item/index.md) | The parent item |
| `$child` | [`Item`](/docs/api/yii/rbac/item/index.md) | The child item to be added to the hierarchy |

**Returns**

`bool`: Whether a loop exists

### getChildrenList() <span id="method-getChildrenList"></span>

```php
protected function getChildrenList(): array
```

Returns the children for every parent.

**Returns**

`array`: The children list. Each array key is a parent item name, and the corresponding array value is a list of child item names.

### getChildrenRecursive() <span id="method-getChildrenRecursive"></span>

```php
protected function getChildrenRecursive(string $name, array $childrenList, array &$result): mixed
```

Recursively finds all children and grand children of the specified item.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name of the item whose children are to be looked for. |
| `$childrenList` | `array` | The child list built via [`getChildrenList()`](/docs/api/yii/rbac/dbmanager/index.md#method-getChildrenList) |
| `$result` | `array` | The children and grand children (in array keys) |

**Returns**

`mixed`

### getDirectPermissionsByUser() <span id="method-getDirectPermissionsByUser"></span>

```php
protected function getDirectPermissionsByUser(string|int $userId): yii\rbac\Permission[]
```

Returns all permissions that are directly assigned to user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `string\|int` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

[`Permission`](/docs/api/yii/rbac/permission/index.md)`[]`: All direct permissions that the user has. The array is indexed by the permission names.

**Since**

2.0.7

### getInheritedPermissionsByUser() <span id="method-getInheritedPermissionsByUser"></span>

```php
protected function getInheritedPermissionsByUser(string|int $userId): yii\rbac\Permission[]
```

Returns all permissions that the user inherits from the roles assigned to him.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `string\|int` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

[`Permission`](/docs/api/yii/rbac/permission/index.md)`[]`: All inherited permissions that the user has. The array is indexed by the permission names.

**Since**

2.0.7

### getItem() <span id="method-getItem"></span>

```php
protected function getItem(mixed $name): yii\rbac\Item|null
```

Returns the named auth item.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The auth item name. |

**Returns**

[`Item`](/docs/api/yii/rbac/item/index.md)`|null`: The auth item corresponding to the specified name. Null is returned if no such item.

### getItems() <span id="method-getItems"></span>

```php
protected function getItems(mixed $type): ($type is yii\rbac\Item::TYPE_ROLE ? yii\rbac\Role[] : yii\rbac\Permission[])
```

Returns the items of the specified type.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `mixed` | The auth item type (either [`Item::TYPE_ROLE`](/docs/api/yii/rbac/item/index.md#const-TYPE_ROLE) or [`Item::TYPE_PERMISSION`](/docs/api/yii/rbac/item/index.md#const-TYPE_PERMISSION) |

**Returns**

`($type is` [`Item`](/docs/api/yii/rbac/item/index.md)`::TYPE_ROLE ?` [`Role`](/docs/api/yii/rbac/role/index.md)`[] :` [`Permission`](/docs/api/yii/rbac/permission/index.md)`[])`: The auth items of the specified type.

### isEmptyUserId() <span id="method-isEmptyUserId"></span>

```php
protected function isEmptyUserId(mixed $userId): bool
```

Check whether $userId is empty.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `mixed` |  |

**Returns**

`bool`

**Since**

2.0.26

### populateItem() <span id="method-populateItem"></span>

```php
protected function populateItem(array $row): yii\rbac\Item
```

Populates an auth item with the data fetched from database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$row` | `array` | The data from the auth item table |

**Returns**

[`Item`](/docs/api/yii/rbac/item/index.md): The populated auth item instance (either Role or Permission)

### removeAllItems() <span id="method-removeAllItems"></span>

```php
protected function removeAllItems(int $type): mixed
```

Removes all auth items of the specified type.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `int` | The auth item type (either Item::TYPE_PERMISSION or Item::TYPE_ROLE). |

**Returns**

`mixed`

### removeAllItemsManualCascade() <span id="method-removeAllItemsManualCascade"></span>

```php
protected function removeAllItemsManualCascade(int $type): void
```

Removes all auth items of the given type without relying on FK enforcement.

Used by SQLite. Clears referencing rows in `auth_item_child` (both directions) and `auth_assignment` via a
correlated subquery, then deletes the items themselves.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `int` | The auth item type (either [`Item::TYPE_PERMISSION`](/docs/api/yii/rbac/item/index.md#const-TYPE_PERMISSION) or [`Item::TYPE_ROLE`](/docs/api/yii/rbac/item/index.md#const-TYPE_ROLE)). |

**Since**

22.0

### removeAllItemsSoftCascade() <span id="method-removeAllItemsSoftCascade"></span>

```php
protected function removeAllItemsSoftCascade(int $type): void
```

Removes all auth items of the given type when FKs cascade for every direction except `auth_item_child.child`.

Used by MSSQL. Clears the multi-path direction via a correlated subquery; native cascade handles the rest.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `int` | The auth item type (either [`Item::TYPE_PERMISSION`](/docs/api/yii/rbac/item/index.md#const-TYPE_PERMISSION) or [`Item::TYPE_ROLE`](/docs/api/yii/rbac/item/index.md#const-TYPE_ROLE)). |

**Since**

22.0

### removeAllRulesManualCascade() <span id="method-removeAllRulesManualCascade"></span>

```php
protected function removeAllRulesManualCascade(): void
```

Removes every auth rule without relying on FK enforcement.

Used by SQLite. Nulls out every `auth_item.rule_name` reference before deleting all rule rows.

**Since**

22.0

### removeItem() <span id="method-removeItem"></span>

```php
protected function removeItem(mixed $item): bool
```

Removes an auth item from the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$item` | `mixed` | The item to remove |

**Returns**

`bool`: Whether the role or permission is successfully removed

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the role or permission is not unique)

### removeItemManualCascade() <span id="method-removeItemManualCascade"></span>

```php
protected function removeItemManualCascade(yii\rbac\Item $item): void
```

Removes an item without relying on FK enforcement.

Used by SQLite where foreign keys are not enforced. Deletes referencing rows in `auth_item_child` (both
directions) and `auth_assignment` before deleting the item itself, all inside one transaction so a partial
failure rolls back.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$item` | [`Item`](/docs/api/yii/rbac/item/index.md) | The item to remove. |

**Since**

22.0

### removeItemSoftCascade() <span id="method-removeItemSoftCascade"></span>

```php
protected function removeItemSoftCascade(yii\rbac\Item $item): void
```

Removes an item when FKs cascade for every direction except `auth_item_child.child`.

Used by MSSQL where the multi-path constraint forces the `auth_item_child.child` FK to `NO ACTION`. That
direction is cleared explicitly; the rest (`auth_item_child.parent`, `auth_assignment`) cascades natively.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$item` | [`Item`](/docs/api/yii/rbac/item/index.md) | The item to remove. |

**Since**

22.0

### removeRule() <span id="method-removeRule"></span>

```php
protected function removeRule(mixed $rule): bool
```

Removes a rule from the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rule` | `mixed` | The rule to remove |

**Returns**

`bool`: Whether the rule is successfully removed

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the rule is not unique)

### removeRuleManualCascade() <span id="method-removeRuleManualCascade"></span>

```php
protected function removeRuleManualCascade(yii\rbac\Rule $rule): void
```

Removes a rule without relying on FK enforcement.

Used by SQLite. Nulls out `auth_item.rule_name` references before deleting the rule itself.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rule` | [`Rule`](/docs/api/yii/rbac/rule/index.md) | The rule to remove. |

**Since**

22.0

### requiresSoftCascade() <span id="method-requiresSoftCascade"></span>

```php
protected function requiresSoftCascade(): bool
```

Returns whether the driver requires a partial PHP-level cleanup of `auth_item_child` rows whose `child` column
references the affected item.

MSSQL rejects `ON DELETE CASCADE` / `ON UPDATE CASCADE` on the second FK from `auth_item_child` to
`auth_item.name` (multi-path constraint), so the `child` direction is left as `NO ACTION` in the schema and
must be cleaned up explicitly before the parent row is deleted or renamed. The other RBAC FKs cascade natively.

Default returns `true` for MSSQL drivers. Subclasses can override to register custom drivers with the same
limitation.

**Returns**

`bool`: Whether the `auth_item_child.child` direction must be handled in PHP.

**Since**

22.0

### supportsCascadeUpdate() <span id="method-supportsCascadeUpdate"></span>

```php
protected function supportsCascadeUpdate(): bool
```

Returns whether the database performs cascade updates and deletes automatically (for example, via FK
`ON UPDATE CASCADE` / `ON DELETE CASCADE`).

Default returns `false` only for SQLite (no FK enforcement). MySQL, PostgreSQL, and MSSQL return `true` because
their RBAC schemas declare `ON UPDATE CASCADE` / `ON DELETE CASCADE` (with the multi-path exception on
`auth_item_child.child` for MSSQL — see [`requiresSoftCascade()`](/docs/api/yii/rbac/dbmanager/index.md#method-requiresSoftCascade)). Subclasses can override to register
custom drivers.

**Returns**

`bool`: Whether the database supports cascading update and delete.

### updateItem() <span id="method-updateItem"></span>

```php
protected function updateItem(mixed $name, mixed $item): bool
```

Updates an auth item in the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The name of the item being updated |
| `$item` | `mixed` | The updated item |

**Returns**

`bool`: Whether the auth item is successfully updated

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the role or permission is not unique)

### updateItemManualCascade() <span id="method-updateItemManualCascade"></span>

```php
protected function updateItemManualCascade(string $oldName, yii\rbac\Item $item): void
```

Renames an item without relying on FK enforcement.

Used by SQLite. Directly updates referencing rows in `auth_item_child` (both directions) and `auth_assignment`
before renaming the item itself, all inside one transaction.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$oldName` | `string` | The current name of the item. |
| `$item` | [`Item`](/docs/api/yii/rbac/item/index.md) | The item carrying the new field values. |

**Since**

22.0

### updateItemSoftCascade() <span id="method-updateItemSoftCascade"></span>

```php
protected function updateItemSoftCascade(string $oldName, yii\rbac\Item $item): void
```

Renames an item when FKs cascade for every direction except `auth_item_child.child` (MSSQL multi-path).

Snapshots the affected rows, deletes them, renames the parent (the DB cascades `auth_item_child.parent` and
`auth_assignment.item_name`), and re-inserts the snapshot under the new name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$oldName` | `string` | The current name of the item. |
| `$item` | [`Item`](/docs/api/yii/rbac/item/index.md) | The item carrying the new field values. |

**Since**

22.0

### updateRule() <span id="method-updateRule"></span>

```php
protected function updateRule(mixed $name, mixed $rule): bool
```

Updates a rule to the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The name of the rule being updated |
| `$rule` | `mixed` | The updated rule |

**Returns**

`bool`: Whether the rule is successfully updated

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the rule is not unique)

### updateRuleManualCascade() <span id="method-updateRuleManualCascade"></span>

```php
protected function updateRuleManualCascade(string $oldName, yii\rbac\Rule $rule): void
```

Renames a rule without relying on FK enforcement.

Used by SQLite. Directly updates `auth_item.rule_name` references before renaming the rule itself.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$oldName` | `string` | The current name of the rule. |
| `$rule` | [`Rule`](/docs/api/yii/rbac/rule/index.md) | The rule carrying the new field values. |

**Since**

22.0