text/x-rust
•
1.20 KB
•
49 lines
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use super::common::AccessType;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "accesses")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub created_at: Option<DateTimeWithTimeZone>,
pub project: Uuid,
pub owner: Uuid,
pub access_type: AccessType,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::Owner",
to = "super::user::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
User,
#[sea_orm(
belongs_to = "super::project::Entity",
from = "Column::Project",
to = "super::project::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Project,
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl Related<super::project::Entity> for Entity {
fn to() -> RelationDef {
Relation::Project.def()
}
}
impl ActiveModelBehavior for ActiveModel {}