- condition = cls(row[0], row[1])
- for title_row in db_conn.exec('SELECT * FROM condition_titles '
- 'WHERE parent_id = ?', (row[0],)):
- condition.title.history[title_row[1]] = title_row[2]
- for desc_row in db_conn.exec('SELECT * FROM condition_descriptions '
- 'WHERE parent_id = ?', (row[0],)):
- condition.description.history[desc_row[1]] = desc_row[2]
- return condition
-
- @classmethod
- def all(cls, db_conn: DatabaseConnection) -> list[Condition]:
- """Collect all Conditions and their VersionedAttributes."""
- conditions = {}
- for id_, condition in db_conn.cached_conditions.items():
- conditions[id_] = condition
- already_recorded = conditions.keys()
- for row in db_conn.exec('SELECT id FROM conditions'):
- if row[0] not in already_recorded:
- condition = cls.by_id(db_conn, row[0])
- conditions[condition.id_] = condition
- return list(conditions.values())
-
- @classmethod
- def by_id(cls, db_conn: DatabaseConnection, id_: int | None,
- create: bool = False) -> Condition:
- """Collect (or create) Condition and its VersionedAttributes."""
- condition = None
- if id_ in db_conn.cached_conditions.keys():
- condition = db_conn.cached_conditions[id_]
- else:
- for row in db_conn.exec('SELECT * FROM conditions WHERE id = ?',
- (id_,)):
- condition = cls.from_table_row(db_conn, row)
- break
- if not condition:
- if not create:
- raise NotFoundException(f'Condition not found of id: {id_}')
- condition = cls(id_, False)
+ condition = super().from_table_row(db_conn, row)
+ for name in ('title', 'description'):
+ table_name = f'condition_{name}s'
+ for row_ in db_conn.row_where(table_name, 'parent', row[0]):
+ getattr(condition, name).history_from_row(row_)