changeset 4161:2074b2bbe616

core (memory/sqla_mapping): `delete-orphan` in History: add `cascade=delete-orphan` to History's `messages`, `subjects` and `thread`, to make modification of those attributes easier.
author Goffi <goffi@goffi.org>
date Tue, 28 Nov 2023 17:35:20 +0100
parents 6a0066ea5c97
children 98687eaa6a09
files libervia/backend/memory/sqla_mapping.py
diffstat 1 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/backend/memory/sqla_mapping.py	Tue Nov 28 17:26:45 2023 +0100
+++ b/libervia/backend/memory/sqla_mapping.py	Tue Nov 28 17:35:20 2023 +0100
@@ -299,10 +299,24 @@
     extra = Column(LegacyPickle)
 
     profile = relationship("Profile")
-    messages = relationship("Message", backref="history", passive_deletes=True)
-    subjects = relationship("Subject", backref="history", passive_deletes=True)
+    messages = relationship(
+        "Message",
+        backref="history",
+        cascade="all, delete-orphan",
+        passive_deletes=True
+    )
+    subjects = relationship(
+        "Subject",
+        backref="history",
+        cascade="all, delete-orphan",
+        passive_deletes=True
+    )
     thread = relationship(
-        "Thread", uselist=False, back_populates="history", passive_deletes=True
+        "Thread",
+        uselist=False,
+        back_populates="history",
+        cascade="all, delete-orphan",
+        passive_deletes=True
     )
     __mapper_args__ = {"version_id_col": version_id}