+ @property
+ def as_dict(self) -> dict[str, object]:
+ """Return self as (json.dumps-coompatible) dict."""
+ d = super().as_dict
+ assert isinstance(d['_library'], dict)
+ d['todos'] = [t.as_dict_into_reference(d['_library'])
+ for t in self.todos]
+ return d
+
+ @classmethod
+ def from_table_row(cls, db_conn: DatabaseConnection, row: Row | list[Any]
+ ) -> Day:
+ """Make from DB row, with linked Todos."""
+ day = super().from_table_row(db_conn, row)
+ assert isinstance(day.id_, str)
+ day.todos = Todo.by_date(db_conn, day.id_)
+ return day
+
+ @classmethod
+ def by_id(cls, db_conn: DatabaseConnection, id_: str) -> Day:
+ """Extend BaseModel.by_id checking for new/lost .todos."""
+ day = super().by_id(db_conn, id_)
+ if day.id_ in Todo.days_to_update:
+ Todo.days_to_update.remove(day.id_)
+ day.todos = Todo.by_date(db_conn, day.id_)
+ return day
+