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: PathBytes,
29 pub relative_poster_path: Option<PathBytes>,
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}
57
58impl Related<super::collections::Entity> for Entity {
59 fn to() -> RelationDef {
60 Relation::Parent.def()
61 }
62}
63
64impl Related<super::libraries::Entity> for Entity {
65 fn to() -> RelationDef {
66 Relation::Library.def()
67 }
68}