server: Add a table for ingredients

This commit is contained in:
traxys 2023-05-29 21:00:40 +02:00
parent f88aecd306
commit d5f3edc33f
7 changed files with 101 additions and 2 deletions

View file

@ -11,7 +11,16 @@ pub struct Model {
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
pub enum Relation {
#[sea_orm(has_many = "super::ingredient::Entity")]
Ingredient,
}
impl Related<super::ingredient::Entity> for Entity {
fn to() -> RelationDef {
Relation::Ingredient.def()
}
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {

33
src/entity/ingredient.rs Normal file
View file

@ -0,0 +1,33 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "ingredient")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub household: Uuid,
pub name: String,
pub unit: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::household::Entity",
from = "Column::Household",
to = "super::household::Column::Id",
on_update = "Restrict",
on_delete = "Restrict"
)]
Household,
}
impl Related<super::household::Entity> for Entity {
fn to() -> RelationDef {
Relation::Household.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -4,4 +4,5 @@ pub mod prelude;
pub mod household;
pub mod household_members;
pub mod ingredient;
pub mod user;

View file

@ -2,4 +2,5 @@
pub use super::household::Entity as Household;
pub use super::household_members::Entity as HouseholdMembers;
pub use super::ingredient::Entity as Ingredient;
pub use super::user::Entity as User;