home · contact · privacy
Refactor BaseModel.from_table_row in regards to VersionedAttributes.
[plomtask] / plomtask / db.py
index 054060e13b7c1fa4aa27274efab13ff1c2828815..3917ce0558e3f7deb1f917a07eb5dd4df7b279e6 100644 (file)
@@ -369,8 +369,14 @@ class BaseModel(Generic[BaseModelId]):
                        # pylint: disable=unused-argument
                        db_conn: DatabaseConnection,
                        row: Row | list[Any]) -> BaseModelInstance:
-        """Make from DB row, update DB cache with it."""
+        """Make from DB row (sans relations), update DB cache with it."""
         obj = cls(*row)
+        assert obj.id_ is not None
+        for attr_name in cls.to_save_versioned:
+            attr = getattr(obj, attr_name)
+            table_name = attr.table_name
+            for row_ in db_conn.row_where(table_name, 'parent', obj.id_):
+                attr.history_from_row(row_)
         obj._cache()
         return obj