- def from_table_row(cls, db_conn: DatabaseConnection, row: Row) -> Day:
- """Make Day from database row, write to cache."""
- day = cls(row[0], row[1])
- db_conn.cached_days[day.date] = day
+ def from_table_row(cls, db_conn: DatabaseConnection, row: Row | list[Any]
+ ) -> Day:
+ """Make from DB row, with linked Todos."""
+ # pylint: disable=protected-access
+ # (since on ._todo we're only meddling within cls)
+ 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 | None,
+ create: bool = False,
+ init_empty_todo_list: bool = False
+ ) -> Day:
+ """Extend BaseModel.by_id with init_empty_todo_list flag."""
+ # pylint: disable=protected-access
+ # (since on ._todo we're only meddling within cls)
+ day = super().by_id(db_conn, id_, create)
+ if init_empty_todo_list and day._todos is None:
+ day._todos = []