flix_db/entity/tmdb/
collections.rs

1//! Collection entity
2
3use flix_model::id::CollectionId as FlixId;
4use flix_tmdb::model::id::CollectionId;
5
6use chrono::NaiveDate;
7use sea_orm::{
8	ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
9	EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
10};
11
12/// The database representation of a tmdb collection
13#[derive(Debug, Clone, DeriveEntityModel)]
14#[sea_orm(table_name = "flix_tmdb_collections")]
15pub struct Model {
16	/// The collection's TMDB ID
17	#[sea_orm(primary_key, auto_increment = false)]
18	pub tmdb_id: CollectionId,
19	/// The collection's ID
20	pub flix_id: FlixId,
21	/// The date of the last update
22	pub last_update: NaiveDate,
23	/// The number of movies in the collection
24	pub movie_count: u16,
25}
26
27impl ActiveModelBehavior for ActiveModel {}
28
29/// Relation
30#[derive(Debug, EnumIter, DeriveRelation)]
31pub enum Relation {
32	/// The movies that are part of this collection
33	#[sea_orm(has_many = "super::movies::Entity")]
34	Movies,
35}
36
37impl Related<super::movies::Entity> for Entity {
38	fn to() -> RelationDef {
39		Relation::Movies.def()
40	}
41}