From 6099b877c0e656207e2c9f75627e1f5bdf7f3e91 Mon Sep 17 00:00:00 2001 From: Aleksandr Zonis Date: Tue, 8 Jan 2019 12:47:31 -0600 Subject: [PATCH] Fixing bug in database_setup.py, make deleting restaurant more efficient Allows to delete menu items, if restaurant is deleted. --- Lesson4/step2/database_setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lesson4/step2/database_setup.py b/Lesson4/step2/database_setup.py index f49c971..a5ec291 100644 --- a/Lesson4/step2/database_setup.py +++ b/Lesson4/step2/database_setup.py @@ -1,6 +1,6 @@ from sqlalchemy import Column, ForeignKey, Integer, String from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import relationship +from sqlalchemy.orm import relationship, backref from sqlalchemy import create_engine Base = declarative_base() @@ -41,7 +41,7 @@ class MenuItem(Base): price = Column(String(8)) course = Column(String(250)) restaurant_id = Column(Integer, ForeignKey('restaurant.id')) - restaurant = relationship(Restaurant) + restaurant = relationship(Restaurant, backref=backref("items", cascade="all,delete")) user_id = Column(Integer, ForeignKey('user.id')) user = relationship(User)