flix_db/entity/content/
shows.rs1use flix_model::id::{CollectionId, LibraryId, ShowId};
4
5use seamantic::model::path::PathBytes;
6
7use sea_orm::{
8 ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
9 EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
10};
11
12#[derive(Debug, Clone, DeriveEntityModel)]
14#[sea_orm(table_name = "flix_shows")]
15pub struct Model {
16 #[sea_orm(primary_key, auto_increment = false)]
18 pub id: ShowId,
19 pub parent: Option<CollectionId>,
21 pub slug: String,
23 pub library: LibraryId,
25 pub directory: PathBytes,
27 pub relative_poster_path: Option<String>,
29}
30
31impl ActiveModelBehavior for ActiveModel {}
32
33#[derive(Debug, EnumIter, DeriveRelation)]
35pub enum Relation {
36 #[sea_orm(
38 belongs_to = "super::collections::Entity",
39 from = "Column::Parent",
40 to = "super::collections::Column::Id",
41 on_update = "Cascade",
42 on_delete = "Cascade"
43 )]
44 Parent,
45 #[sea_orm(
47 belongs_to = "super::libraries::Entity",
48 from = "Column::Library",
49 to = "super::libraries::Column::Id",
50 on_update = "Cascade",
51 on_delete = "Cascade"
52 )]
53 Library,
54 #[sea_orm(
56 belongs_to = "super::super::info::shows::Entity",
57 from = "Column::Id",
58 to = "super::super::info::shows::Column::Id",
59 on_update = "Cascade",
60 on_delete = "Cascade"
61 )]
62 MediaInfo,
63 #[sea_orm(
65 belongs_to = "super::super::watched::shows::Entity",
66 from = "Column::Id",
67 to = "super::super::watched::shows::Column::Id",
68 on_update = "Cascade",
69 on_delete = "Cascade"
70 )]
71 WatchInfo,
72}
73
74impl Related<super::collections::Entity> for Entity {
75 fn to() -> RelationDef {
76 Relation::Parent.def()
77 }
78}
79
80impl Related<super::libraries::Entity> for Entity {
81 fn to() -> RelationDef {
82 Relation::Library.def()
83 }
84}
85
86impl Related<super::super::info::shows::Entity> for Entity {
87 fn to() -> RelationDef {
88 Relation::MediaInfo.def()
89 }
90}
91
92impl Related<super::super::watched::shows::Entity> for Entity {
93 fn to() -> RelationDef {
94 Relation::WatchInfo.def()
95 }
96}