From 722db5feae27808b6beb64c3afc7eceef0d77db9 Mon Sep 17 00:00:00 2001 From: Raphael Maenle Date: Wed, 27 May 2020 20:56:23 +0200 Subject: [PATCH] delete now uses orphan cascade deletion instead of manual delete --- database/models.py | 6 +++--- server/routes.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/database/models.py b/database/models.py index f5c9cac..35bbbd3 100644 --- a/database/models.py +++ b/database/models.py @@ -14,9 +14,9 @@ class User(UserMixin, db.Model): email = db.Column(db.String(120), index=True, unique=True) profile_pic = db.Column(db.String(256)) password_hash = db.Column(db.String(128)) - google_token = db.relationship('GoogleToken', uselist=False, backref = 'user') - calendars = db.relationship('Calendar', backref='user', lazy=True) - devices = db.relationship('Device', backref='user') + google_token = db.relationship('GoogleToken', uselist=False, backref = 'user', cascade="all, delete-orphan") + calendars = db.relationship('Calendar', backref='user', lazy=True, cascade="all, delete-orphan") + devices = db.relationship('Device', backref='user', cascade="all, delete-orphan") def __repr__(self): return ''.format(self.username) diff --git a/server/routes.py b/server/routes.py index 820dfc6..0060ab3 100644 --- a/server/routes.py +++ b/server/routes.py @@ -107,13 +107,13 @@ def deleteAccount(): return redirect(url_for('account')) # TODO fix google delete account google.deleteAccount(current_user) - + ''' for cal in current_user.calendars: db.session.delete(cal) for dev in current_user.devices: db.session.delete(dev) - db.session.delete(current_user.google_token) + ''' db.session.delete(current_user) db.session.commit() logout_user()