# `PhoenixKit.Users.RoleAssignment`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.165/lib/phoenix_kit/users/role_assignment.ex#L1)

Role assignment schema for PhoenixKit authorization system.

This schema represents the many-to-many relationship between users and roles,
with additional metadata about when and by whom the role was assigned.

## Fields

- `user_uuid`: UUID reference to the user who has the role
- `role_uuid`: UUID reference to the role being assigned
- `assigned_by_uuid`: UUID reference to the user who assigned this role (can be nil for system assignments)
- `assigned_at`: Timestamp when the role was assigned

## Features

- Tracks role assignment history
- Supports bulk role management
- Audit trail for security purposes
- Direct deletion for role removal

# `t`

```elixir
@type t() :: %PhoenixKit.Users.RoleAssignment{
  __meta__: term(),
  assigned_at: DateTime.t(),
  assigned_by_user: term(),
  assigned_by_uuid: UUIDv7.t() | nil,
  inserted_at: DateTime.t(),
  role: term(),
  role_uuid: UUIDv7.t() | nil,
  user: term(),
  user_uuid: UUIDv7.t() | nil,
  uuid: UUIDv7.t() | nil
}
```

# `changeset`

A role assignment changeset for creating role assignments.

## Parameters

- `role_assignment`: The role assignment struct to modify
- `attrs`: Attributes to update

## Examples

    iex> changeset(%RoleAssignment{}, %{user_uuid: "...", role_uuid: "..."})
    %Ecto.Changeset{valid?: true}

    iex> changeset(%RoleAssignment{}, %{})
    %Ecto.Changeset{valid?: false}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
