flix_db/entity/content/
seasons.rs1use flix_model::id::{LibraryId, ShowId};
4
5use seamantic::model::path::PathBytes;
6
7use flix_model::numbers::SeasonNumber;
8use sea_orm::{
9 ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
10 EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
11};
12
13#[derive(Debug, Clone, DeriveEntityModel)]
15#[sea_orm(table_name = "flix_seasons")]
16pub struct Model {
17 #[sea_orm(primary_key, auto_increment = false)]
19 pub show: ShowId,
20 #[sea_orm(primary_key, auto_increment = false)]
22 pub season: SeasonNumber,
23 pub slug: String,
25 pub library: LibraryId,
27 pub directory: PathBytes,
29 pub relative_poster_path: Option<String>,
31}
32
33impl ActiveModelBehavior for ActiveModel {}
34
35#[derive(Debug, EnumIter, DeriveRelation)]
37pub enum Relation {
38 #[sea_orm(
40 belongs_to = "super::libraries::Entity",
41 from = "Column::Library",
42 to = "super::libraries::Column::Id",
43 on_update = "Cascade",
44 on_delete = "Cascade"
45 )]
46 Library,
47 #[sea_orm(
49 belongs_to = "super::super::info::seasons::Entity",
50 from = "(Column::Show, Column::Season)",
51 to = "(super::super::info::seasons::Column::Show, super::super::info::seasons::Column::Season)",
52 on_update = "Cascade",
53 on_delete = "Cascade"
54 )]
55 MediaInfo,
56 #[sea_orm(
58 belongs_to = "super::super::watched::seasons::Entity",
59 from = "(Column::Show, Column::Season)",
60 to = "(super::super::watched::seasons::Column::Show, super::super::watched::seasons::Column::Season)",
61 on_update = "Cascade",
62 on_delete = "Cascade"
63 )]
64 WatchInfo,
65}
66
67impl Related<super::libraries::Entity> for Entity {
68 fn to() -> RelationDef {
69 Relation::Library.def()
70 }
71}
72
73impl Related<super::super::info::seasons::Entity> for Entity {
74 fn to() -> RelationDef {
75 Relation::MediaInfo.def()
76 }
77}
78
79impl Related<super::super::watched::seasons::Entity> for Entity {
80 fn to() -> RelationDef {
81 Relation::WatchInfo.def()
82 }
83}