diff --git a/src/allocation/adapters/orm.py b/src/allocation/adapters/orm.py index a87068a5..95c0a285 100644 --- a/src/allocation/adapters/orm.py +++ b/src/allocation/adapters/orm.py @@ -8,7 +8,7 @@ ForeignKey, event, ) -from sqlalchemy.orm import mapper, relationship +from sqlalchemy.orm import relationship, registry from allocation.domain import model @@ -57,10 +57,13 @@ Column("batchref", String(255)), ) +# Create a registry +mapper_registry = registry() + def start_mappers(): - lines_mapper = mapper(model.OrderLine, order_lines) - batches_mapper = mapper( + lines_mapper = mapper_registry.map_imperatively(model.OrderLine, order_lines) + batches_mapper = mapper_registry.map_imperatively( model.Batch, batches, properties={ @@ -71,7 +74,7 @@ def start_mappers(): ) }, ) - mapper( + mapper_registry.map_imperatively( model.Product, products, properties={"batches": relationship(batches_mapper)},