# UserRole

## Description

UserRole is a join model that represents the assignment of a role to a user. This many-to-many relationship enables users to have multiple roles and roles to be assigned to multiple users. Role assignments are only valid for users in ACTIVE status, ensuring that pending or inactive users cannot accumulate permissions.

The assignment operation is idempotent - assigning the same role twice does not create duplicate records.

## Domain Model Definitions

### Model type

Standard

### Command Definitions

- [assignRoleToUser](../commands/AssignRoleToUser.md)
- [revokeRoleFromUser](../commands/RevokeRoleFromUser.md)

### Query Definitions

### Models

- UserRole

### Invariants

- User-Role combination must be unique (no duplicate assignments)
- Referenced user must exist
- Referenced role must exist and be in ACTIVE status
- User must be in ACTIVE status to receive role assignment

### Relationships

- **Belongs To User**: Each UserRole record references exactly one user
- **Belongs To Role**: Each UserRole record references exactly one role
