use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "topics")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub category_id: Uuid,
pub user_id: Uuid,
pub title: String,
pub is_pinned: bool,
pub is_closed: bool,
pub views: i32,
pub posts_count: i32,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
/// Updated whenever a new post is added; used for "latest" ordering.
pub bumped_at: DateTimeWithTimeZone,
/// Soft-delete tombstone — keeps the row (and `/t/{id}` URL) alive so
/// references don't break. Only staff can restore.
pub deleted_at: Option<DateTimeWithTimeZone>,
pub deleted_by_id: Option<Uuid>,
/// The lock (`is_closed`): when, by whom, and why.
pub closed_at: Option<DateTimeWithTimeZone>,
pub closed_by_id: Option<Uuid>,
pub closed_reason: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::categories::Entity",
from = "Column::CategoryId",
to = "super::categories::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Categories,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Users,
#[sea_orm(has_many = "super::posts::Entity")]
Posts,
}
impl Related<super::categories::Entity> for Entity {
fn to() -> RelationDef {
Relation::Categories.def()
}
}
impl Related<super::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}
impl Related<super::posts::Entity> for Entity {
fn to() -> RelationDef {
Relation::Posts.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions running · Badges · Packages
⭐
Log in to mark this repository.
2.0 KiB · text
History
3d71adc