server: Link recipe to households

This commit is contained in:
traxys 2023-06-22 23:03:50 +02:00
parent cec3ef214e
commit 69197a3852
4 changed files with 35 additions and 1 deletions

View file

@ -14,6 +14,8 @@ pub struct Model {
pub enum Relation {
#[sea_orm(has_many = "super::ingredient::Entity")]
Ingredient,
#[sea_orm(has_many = "super::recipe::Entity")]
Recipe,
}
impl Related<super::ingredient::Entity> for Entity {
@ -22,6 +24,12 @@ impl Related<super::ingredient::Entity> for Entity {
}
}
impl Related<super::recipe::Entity> for Entity {
fn to() -> RelationDef {
Relation::Recipe.def()
}
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
super::household_members::Relation::User.def()

View file

@ -10,14 +10,29 @@ pub struct Model {
#[sea_orm(column_type = "Text")]
pub name: String,
pub ranking: i32,
pub household: Uuid,
}
#[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,
#[sea_orm(has_many = "super::recipe_steps::Entity")]
RecipeSteps,
}
impl Related<super::household::Entity> for Entity {
fn to() -> RelationDef {
Relation::Household.def()
}
}
impl Related<super::recipe_steps::Entity> for Entity {
fn to() -> RelationDef {
Relation::RecipeSteps.def()

View file

@ -18,6 +18,7 @@ pub(super) async fn create_recipe(
let model = recipe::ActiveModel {
name: ActiveValue::Set(request.name),
ranking: ActiveValue::Set(request.rating as i32),
household: ActiveValue::Set(household.id),
..Default::default()
};