flix_db/entity/info/
seasons.rs

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