# 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 valid for PENDING and ACTIVE users; INACTIVE users are rejected.

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

## Domain Model Definitions

### Model type

Standard

### Command Definitions

- [assignRoleToUser](../command/AssignRoleToUser.md)
- [revokeRoleFromUser](../command/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 not be in INACTIVE status to receive role assignment (PENDING and ACTIVE are allowed)

### Relationships

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