flix_db/entity/content/
collections.rs1use flix_model::id::{CollectionId, LibraryId};
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_collections")]
15pub struct Model {
16 #[sea_orm(primary_key, auto_increment = false)]
18 pub id: CollectionId,
19 pub parent: Option<CollectionId>,
21 pub slug: String,
23 pub library: LibraryId,
25 pub directory: PathBytes,
27 pub relative_poster_path: Option<PathBytes>,
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}
55
56impl Related<super::collections::Entity> for Entity {
57 fn to() -> RelationDef {
58 Relation::Parent.def()
59 }
60}
61
62impl Related<super::libraries::Entity> for Entity {
63 fn to() -> RelationDef {
64 Relation::Library.def()
65 }
66}