1011 B · text History 263b40b
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

/// How far a user has read a topic (drives the "new" / "N unread" markers).
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "topic_reads")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub user_id: Uuid,
    #[sea_orm(primary_key, auto_increment = false)]
    pub topic_id: Uuid,
    pub last_read_post_number: i32,
    pub updated_at: DateTimeWithTimeZone,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::users::Entity",
        from = "Column::UserId",
        to = "super::users::Column::Id",
        on_delete = "Cascade"
    )]
    Users,
    #[sea_orm(
        belongs_to = "super::topics::Entity",
        from = "Column::TopicId",
        to = "super::topics::Column::Id",
        on_delete = "Cascade"
    )]
    Topics,
}

impl ActiveModelBehavior for ActiveModel {}