user_role.rs 43 lignes · 1272 octets
use chrono::{DateTime, Utc};
use sea_orm::entity::prelude::*;
use uuid::Uuid;

/// UserRole junction entity model
///
/// Represents the many-to-many relationship between users and roles.
/// This is a junction table with a composite primary key.
#[derive(Clone, Debug, DeriveEntityModel)]
#[sea_orm(table_name = "user_roles")]
pub struct Model {
    /// Reference to the user (part of composite primary key)
    #[sea_orm(primary_key)]
    pub user_id: Uuid,
    /// Reference to the role (part of composite primary key)
    #[sea_orm(primary_key)]
    pub role_id: Uuid,
    /// Creation timestamp
    pub created_at: DateTime<Utc>,
}

/// SeaORM relations for the UserRole junction entity.
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    /// The user side of the user-role junction.
    #[sea_orm(
        belongs_to = "super::user::Entity",
        from = "Column::UserId",
        to = "super::user::Column::Id",
        on_delete = "Cascade"
    )]
    User,
    /// The role side of the user-role junction.
    #[sea_orm(
        belongs_to = "super::role::Entity",
        from = "Column::RoleId",
        to = "super::role::Column::Id",
        on_delete = "Cascade"
    )]
    Role,
}

impl ActiveModelBehavior for ActiveModel {}