Skip to main content

crosup_entity/
modification.rs

1use sea_orm::entity::prelude::*;
2use sea_orm::DeriveEntityModel;
3
4#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
5#[sea_orm(table_name = "modification")]
6pub struct Model {
7    #[sea_orm(primary_key)]
8    pub id: i32,
9    #[sea_orm(column_type = "Timestamp")]
10    pub timestamp: chrono::NaiveDateTime,
11    pub hash: String,
12    pub file_id: i32,
13    pub previous_id: Option<i32>,
14    #[sea_orm(column_type = "Text")]
15    pub content: String,
16}
17
18#[derive(Copy, Clone, Debug, EnumIter)]
19pub enum Relation {
20    File,
21    Modification,
22}
23
24impl RelationTrait for Relation {
25    fn def(&self) -> RelationDef {
26        match self {
27            Self::File => Entity::belongs_to(super::file::Entity)
28                .from(Column::FileId)
29                .to(super::file::Column::Id)
30                .into(),
31            Self::Modification => Entity::has_one(super::modification::Entity)
32                .from(Column::Id)
33                .to(super::modification::Column::PreviousId)
34                .into(),
35        }
36    }
37}
38
39impl Related<super::file::Entity> for Entity {
40    fn to() -> RelationDef {
41        Relation::File.def()
42    }
43}
44
45impl Related<super::modification::Entity> for Entity {
46    fn to() -> RelationDef {
47        Relation::Modification.def()
48    }
49}
50
51impl ActiveModelBehavior for ActiveModel {}