42 lines
974 B
Rust
42 lines
974 B
Rust
use sea_orm::entity::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
use utoipa::ToSchema;
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize, ToSchema)]
|
|
#[sea_orm(table_name = "category")]
|
|
pub struct Model {
|
|
#[sea_orm(primary_key)]
|
|
pub id: i32,
|
|
pub family_id: i32,
|
|
pub name: String,
|
|
pub limit_amount: Decimal,
|
|
pub created_at: DateTime,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
pub enum Relation {
|
|
#[sea_orm(
|
|
belongs_to = "super::family::Entity",
|
|
from = "Column::FamilyId",
|
|
to = "super::family::Column::Id"
|
|
)]
|
|
Family,
|
|
|
|
#[sea_orm(has_many = "super::expense::Entity")]
|
|
Expense,
|
|
}
|
|
|
|
impl Related<super::family::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Family.def()
|
|
}
|
|
}
|
|
|
|
impl Related<super::expense::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Expense.def()
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|