raise NotFoundException('Process of Todo without ID (not saved?)')
self.save_core(db_conn)
assert isinstance(self.id_, int)
+ db_conn.rewrite_relations('todo_children', 'child', self.id_,
+ [[p.id_] for p in self.parents])
db_conn.rewrite_relations('todo_children', 'parent', self.id_,
[[c.id_] for c in self.children])
db_conn.rewrite_relations('todo_conditions', 'todo', self.id_,
def remove(self, db_conn: DatabaseConnection) -> None:
"""Remove from DB, including relations."""
assert isinstance(self.id_, int)
- for child in self.children:
+ children_to_remove = self.children[:]
+ parents_to_remove = self.parents[:]
+ for child in children_to_remove:
self.remove_child(child)
- for parent in self.parents:
+ for parent in parents_to_remove:
parent.remove_child(self)
+ db_conn.delete_where('todo_children', 'parent', self.id_)
+ db_conn.delete_where('todo_children', 'child', self.id_)
db_conn.delete_where('todo_conditions', 'todo', self.id_)
db_conn.delete_where('todo_enables', 'todo', self.id_)
db_conn.delete_where('todo_disables', 'todo', self.id_)