From 1d7f87a7a02ab4cd68e3ba381352ec00af9ca8ee Mon Sep 17 00:00:00 2001 From: Anatoly Bogomolov Date: Thu, 1 Feb 2024 19:08:48 +1000 Subject: [PATCH] delete users and tasks when session was deleted --- app/models/session.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/session.py b/app/models/session.py index 900c8e7..3c59e58 100644 --- a/app/models/session.py +++ b/app/models/session.py @@ -10,9 +10,9 @@ class Session(db.Model): name: Mapped[str] = mapped_column(unique=True) authorized: Mapped[bool] - users: Mapped[List[User]] = relationship("User", back_populates="session") + users: Mapped[List[User]] = relationship("User", cascade="all, delete-orphan", back_populates="session") - tasks: Mapped[List[Task]] = relationship("Task", back_populates="session") + tasks: Mapped[List[Task]] = relationship("Task", cascade="all, delete-orphan", back_populates="session") def has_depending_tasks(self): tasks = Task.query \