flix_db/entity/content/
seasons.rs

1//! Season entity
2
3use 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/// The database representation of a season media folder
14#[derive(Debug, Clone, DeriveEntityModel)]
15#[sea_orm(table_name = "flix_seasons")]
16pub struct Model {
17	/// The season's show's ID
18	#[sea_orm(primary_key, auto_increment = false)]
19	pub show: ShowId,
20	/// The season's number
21	#[sea_orm(primary_key, auto_increment = false)]
22	pub season: SeasonNumber,
23	/// The season's slug
24	pub slug: String,
25	/// The season's library
26	pub library: LibraryId,
27	/// The season's directory
28	pub directory: PathBytes,
29	/// The season's poster path
30	pub relative_poster_path: Option<PathBytes>,
31}
32
33impl ActiveModelBehavior for ActiveModel {}
34
35/// Relation
36#[derive(Debug, EnumIter, DeriveRelation)]
37pub enum Relation {
38	/// The library this season belongs to
39	#[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}
48
49impl Related<super::libraries::Entity> for Entity {
50	fn to() -> RelationDef {
51		Relation::Library.def()
52	}
53}