2023-12-13 12:32:01 +08:00
|
|
|
use sea_orm::entity::prelude::*;
|
2023-12-25 10:17:13 +08:00
|
|
|
use serde::{ Deserialize, Serialize };
|
2023-12-13 12:32:01 +08:00
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
|
2023-12-13 16:44:52 +08:00
|
|
|
#[sea_orm(table_name = "doc2_doc")]
|
2023-12-13 12:32:01 +08:00
|
|
|
pub struct Model {
|
2023-12-19 19:28:01 +08:00
|
|
|
#[sea_orm(primary_key, auto_increment = true)]
|
|
|
|
|
pub id: i64,
|
2023-12-13 16:44:52 +08:00
|
|
|
#[sea_orm(index)]
|
2023-12-13 12:32:01 +08:00
|
|
|
pub parent_id: i64,
|
2023-12-19 19:28:01 +08:00
|
|
|
#[sea_orm(index)]
|
2023-12-13 12:32:01 +08:00
|
|
|
pub did: i64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, EnumIter)]
|
|
|
|
|
pub enum Relation {
|
|
|
|
|
Parent,
|
2023-12-25 10:17:13 +08:00
|
|
|
Child,
|
2023-12-13 12:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RelationTrait for Relation {
|
|
|
|
|
fn def(&self) -> RelationDef {
|
|
|
|
|
match self {
|
2023-12-25 10:17:13 +08:00
|
|
|
Self::Parent =>
|
|
|
|
|
Entity::belongs_to(super::doc_info::Entity)
|
|
|
|
|
.from(Column::ParentId)
|
|
|
|
|
.to(super::doc_info::Column::Did)
|
|
|
|
|
.into(),
|
|
|
|
|
Self::Child =>
|
|
|
|
|
Entity::belongs_to(super::doc_info::Entity)
|
|
|
|
|
.from(Column::Did)
|
|
|
|
|
.to(super::doc_info::Column::Did)
|
|
|
|
|
.into(),
|
2023-12-13 12:32:01 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-25 10:17:13 +08:00
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|