flix_db/entity/tmdb/
seasons.rs

1//! Season entity
2
3use flix_model::id::ShowId as FlixId;
4use flix_model::numbers::SeasonNumber;
5use flix_tmdb::model::id::ShowId;
6
7use chrono::NaiveDate;
8use sea_orm::{
9	ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
10	EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
11};
12
13/// The database representation of a tmdb season
14#[derive(Debug, Clone, DeriveEntityModel)]
15#[sea_orm(table_name = "flix_tmdb_seasons")]
16pub struct Model {
17	/// The season's show's TMDB ID
18	#[sea_orm(primary_key, auto_increment = false)]
19	pub tmdb_show: ShowId,
20	/// The season's TMDB season number
21	#[sea_orm(primary_key, auto_increment = false)]
22	pub tmdb_season: SeasonNumber,
23	/// The season's show's ID
24	pub flix_show: FlixId,
25	/// The season's number
26	pub flix_season: SeasonNumber,
27	/// The date of the last update
28	pub last_update: NaiveDate,
29}
30
31impl ActiveModelBehavior for ActiveModel {}
32
33/// Relation
34#[derive(Debug, EnumIter, DeriveRelation)]
35pub enum Relation {
36	/// The show this season belongs to
37	#[sea_orm(
38		belongs_to = "super::shows::Entity",
39		from = "Column::TmdbShow",
40		to = "super::shows::Column::TmdbId",
41		on_update = "Cascade",
42		on_delete = "Cascade"
43	)]
44	Show,
45}
46
47impl Related<super::shows::Entity> for Entity {
48	fn to() -> RelationDef {
49		Relation::Show.def()
50	}
51}