From 794721a0cbe0fbce922a4a78d899fbce1c65fd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 13 Feb 2022 21:04:24 +0100 Subject: [PATCH] one to many --- mealapi/model/ingredient.py | 3 --- mealapi/model/meal.py | 3 +-- mealapi/model/mealingredient.py | 9 --------- 3 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 mealapi/model/mealingredient.py diff --git a/mealapi/model/ingredient.py b/mealapi/model/ingredient.py index 75b9406..1524f22 100644 --- a/mealapi/model/ingredient.py +++ b/mealapi/model/ingredient.py @@ -1,11 +1,8 @@ #!/usr/bin/env python3 from .db import db -from .mealingredient import MealIngredient class Ingredient(db.Model): __tablename__ = 'Ingredient' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False, unique=True) - value = db.Column(db.String, nullable=False) - items = db.relationship('Meal', secondary=MealIngredient.__tablename__, back_populates='Ingredient') diff --git a/mealapi/model/meal.py b/mealapi/model/meal.py index 8b09c65..eb01a6d 100644 --- a/mealapi/model/meal.py +++ b/mealapi/model/meal.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 from .db import db -from .mealingredient import MealIngredient class Meal(db.Model): @@ -13,4 +12,4 @@ class Meal(db.Model): spicy = db.Column(db.Boolean, nullable=False, default=False) vegan = db.Column(db.Boolean, nullable=False, default=False) glutenfree = db.Column(db.Boolean, nullable=False, default=False) - ingredients = db.relationship('Ingredient', secondary=MealIngredient.__tablename__, back_populates='Meal') + ingredients = db.relationship('Ingredient', backref='Meal', lazy='dynamic') diff --git a/mealapi/model/mealingredient.py b/mealapi/model/mealingredient.py deleted file mode 100644 index e851658..0000000 --- a/mealapi/model/mealingredient.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python3 -from .db import db - - -class MealIngredient(db.Model): - __tablename__ = 'MealIngredient' - id = db.Column(db.Integer, primary_key=True, index=True) - itemId = db.Column(db.Integer, db.ForeignKey('Meal.id')) - detailId = db.Column(db.Integer, db.ForeignKey('Ingredient.id'))