From 9c181eccee0bc576806fc2408f50c13469c7769f Mon Sep 17 00:00:00 2001
From: thomaswoehlke <thomas.woehlke@gmail.com>
Date: Sat, 6 Feb 2021 00:18:39 +0100
Subject: [PATCH] work

---
 src/covid19/blueprints/rki/rki_model_import.py           | 2 +-
 .../blueprints/vaccination/vaccination_model_import.py   | 2 +-
 src/covid19/blueprints/who/who_model.py                  | 9 ++++++---
 src/covid19/blueprints/who/who_model_import.py           | 2 +-
 4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/covid19/blueprints/rki/rki_model_import.py b/src/covid19/blueprints/rki/rki_model_import.py
index a1459226..753e2f05 100644
--- a/src/covid19/blueprints/rki/rki_model_import.py
+++ b/src/covid19/blueprints/rki/rki_model_import.py
@@ -17,7 +17,7 @@ class RkiGermanyDataImportTable(db.Model):
     @classmethod
     def remove_all(cls):
         for one in cls.get_all():
-            db.session.delete(one).cascade()
+            db.session.delete(one)
         db.session.commit()
         return None
 
diff --git a/src/covid19/blueprints/vaccination/vaccination_model_import.py b/src/covid19/blueprints/vaccination/vaccination_model_import.py
index ed90437b..162e77db 100644
--- a/src/covid19/blueprints/vaccination/vaccination_model_import.py
+++ b/src/covid19/blueprints/vaccination/vaccination_model_import.py
@@ -30,7 +30,7 @@ class VaccinationGermanyTimeline(db.Model):
     @classmethod
     def remove_all(cls):
         for one in cls.get_all():
-            db.session.delete(one).cascade()
+            db.session.delete(one)
         db.session.commit()
         return None
 
diff --git a/src/covid19/blueprints/who/who_model.py b/src/covid19/blueprints/who/who_model.py
index e3a2fa8c..733a06d9 100644
--- a/src/covid19/blueprints/who/who_model.py
+++ b/src/covid19/blueprints/who/who_model.py
@@ -44,12 +44,13 @@ class WhoCountry(db.Model):
     region = db.relationship(
         'WhoRegion',
         lazy='joined',
+        cascade='all, delete',
         order_by='WhoRegion.region')
 
     @classmethod
     def remove_all(cls):
         for one in cls.get_all():
-            db.session.delete(one).cascade()
+            db.session.delete(one)
         db.session.commit()
         return None
 
@@ -138,18 +139,20 @@ class WhoGlobalData(db.Model):
     date_reported = db.relationship(
         'WhoDateReported',
         lazy='joined',
+        cascade='all, delete',
         order_by='desc(WhoDateReported.date_reported)')
     country_id = db.Column(db.Integer,
         db.ForeignKey('who_country.id'), nullable=False)
     country = db.relationship(
         'WhoCountry',
         lazy='joined',
+        cascade='all, delete',
         order_by='asc(WhoCountry.country)')
 
     @classmethod
     def remove_all(cls):
-        # TODO: SQLalchemy instead of SQL
-        db.session.execute("delete from " + cls.__tablename__)
+        for one in cls.get_all():
+            db.session.delete(one)
         db.session.commit()
         return None
 
diff --git a/src/covid19/blueprints/who/who_model_import.py b/src/covid19/blueprints/who/who_model_import.py
index 336c5980..984dcc66 100644
--- a/src/covid19/blueprints/who/who_model_import.py
+++ b/src/covid19/blueprints/who/who_model_import.py
@@ -17,7 +17,7 @@ class WhoGlobalDataImportTable(db.Model):
     @classmethod
     def remove_all(cls):
         for one in cls.get_all():
-            db.session.delete(one).cascade()
+            db.session.delete(one)
         db.session.commit()
         return None
 
-- 
GitLab