Search documentation of phoenix_kit

# PhoenixKit.Users.RoleAssignment (phoenix_kit v1.6.19)

View Source

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_id`: Reference to the user who has the role
- `role_id`: Reference to the role being assigned
- `assigned_by`: 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

# Summary

## Types

t()

## Functions

changeset(role_assignment, attrs)

A role assignment changeset for creating role assignments.

# Types

# t()

    @type t() :: %PhoenixKit.Users.RoleAssignment{
      __meta__: term(),
      assigned_at: NaiveDateTime.t(),
      assigned_by: integer() | nil,
      assigned_by_user: term(),
      id: integer() | nil,
      inserted_at: NaiveDateTime.t(),
      role: term(),
      role_id: integer(),
      user: term(),
      user_id: integer()
    }

# Functions

# changeset(role_assignment, attrs)

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_id: 1, role_id: 2})
    %Ecto.Changeset{valid?: true}

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