init feature
This commit is contained in:
@@ -16,6 +16,8 @@ pub struct Model {
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::category::Entity")]
|
||||
Category,
|
||||
#[sea_orm(has_many = "super::shopping_item::Entity")]
|
||||
ShoppingItem,
|
||||
}
|
||||
|
||||
impl Related<super::category::Entity> for Entity {
|
||||
@@ -24,4 +26,10 @@ impl Related<super::category::Entity> for Entity {
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::shopping_item::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::ShoppingItem.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
@@ -2,8 +2,10 @@ pub mod family;
|
||||
pub mod category;
|
||||
pub mod expense;
|
||||
pub mod user;
|
||||
pub mod shopping_item;
|
||||
|
||||
pub use family::Entity as Family;
|
||||
pub use category::Entity as Category;
|
||||
pub use expense::Entity as Expense;
|
||||
pub use user::Entity as User;
|
||||
pub use shopping_item::Entity as ShoppingItem;
|
||||
|
||||
34
backend/src/models/shopping_item.rs
Normal file
34
backend/src/models/shopping_item.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize, ToSchema)]
|
||||
#[sea_orm(table_name = "shopping_item")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub family_id: i32,
|
||||
pub name: String,
|
||||
pub is_purchased: bool,
|
||||
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",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Family,
|
||||
}
|
||||
|
||||
impl Related<super::family::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Family.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
Reference in New Issue
Block a user