flix_db/entity/content/
movies.rs1use flix_model::id::{CollectionId, LibraryId, MovieId};
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_movies")]
15pub struct Model {
16 #[sea_orm(primary_key, auto_increment = false)]
18 pub id: MovieId,
19 pub parent: Option<CollectionId>,
21 pub slug: String,
23 pub library: LibraryId,
25 pub directory: PathBytes,
27 pub relative_media_path: String,
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::collections::Entity",
41 from = "Column::Parent",
42 to = "super::collections::Column::Id",
43 on_update = "Cascade",
44 on_delete = "Cascade"
45 )]
46 Parent,
47 #[sea_orm(
49 belongs_to = "super::libraries::Entity",
50 from = "Column::Library",
51 to = "super::libraries::Column::Id",
52 on_update = "Cascade",
53 on_delete = "Cascade"
54 )]
55 Library,
56 #[sea_orm(
58 belongs_to = "super::super::info::movies::Entity",
59 from = "Column::Id",
60 to = "super::super::info::movies::Column::Id",
61 on_update = "Cascade",
62 on_delete = "Cascade"
63 )]
64 MediaInfo,
65 #[sea_orm(
67 belongs_to = "super::super::watched::movies::Entity",
68 from = "Column::Id",
69 to = "super::super::watched::movies::Column::Id",
70 on_update = "Cascade",
71 on_delete = "Cascade"
72 )]
73 WatchInfo,
74}
75
76impl Related<super::collections::Entity> for Entity {
77 fn to() -> RelationDef {
78 Relation::Parent.def()
79 }
80}
81
82impl Related<super::libraries::Entity> for Entity {
83 fn to() -> RelationDef {
84 Relation::Library.def()
85 }
86}
87
88impl Related<super::super::info::movies::Entity> for Entity {
89 fn to() -> RelationDef {
90 Relation::MediaInfo.def()
91 }
92}
93
94impl Related<super::super::watched::movies::Entity> for Entity {
95 fn to() -> RelationDef {
96 Relation::WatchInfo.def()
97 }
98}