From edd129e532a374a3e36931be055c3650e63f818b Mon Sep 17 00:00:00 2001 From: "J.P. Krauss" Date: Tue, 12 Jul 2022 07:39:15 -0700 Subject: [PATCH] Update ORM Mappings --- sigl/database/orm.py | 53 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/sigl/database/orm.py b/sigl/database/orm.py index 6e02ef5..e4e5c0e 100644 --- a/sigl/database/orm.py +++ b/sigl/database/orm.py @@ -27,20 +27,30 @@ __all__ = ('init_orm', ) def init_orm(): """Initialize the Sigl ORM.""" - # # Access Keys - # db.mapper(AccessKey, access_keys, properties={ - # 'tokens': db.relationship( - # AccessToken, - # backref='accessKey', - # cascade='all, delete-orphan', - # ) - # }) + # Access Keys + db.mapper(AccessKey, access_keys, properties={ + 'tokens': db.relationship( + AccessToken, + back_populates='accessKey', + cascade='all, delete-orphan', + ) + }) - # # Access Tokens - # db.mapper(AccessToken, access_tokens) + # Access Tokens + db.mapper(AccessToken, access_tokens, properties={ + 'accessKey': db.relationship( + AccessKey, + back_populates='tokens', + ) + }) # # List Entries - # db.mapper(ListEntry, list_entries) + db.mapper(ListEntry, list_entries, properties={ + 'shoppingList': db.relationship( + ShoppingList, + back_populates='entries', + ) + }) # Products db.mapper(Product, products, properties={ @@ -49,11 +59,6 @@ def init_orm(): back_populates='product', cascade='all, delete-orphan', ), - # 'shoppingLists': db.relationship( - # ShoppingList, - # backref='product', - # cascade='all, delete-orphan', - # ), }) # Product Locations @@ -64,11 +69,11 @@ def init_orm(): ) }) - # # Shopping Lists - # db.mapper(ShoppingList, lists, properties={ - # 'entries': db.relationship( - # ListEntry, - # backref='shoppingList', - # cascade='all, delete-orphan', - # ) - # }) + # Shopping Lists + db.mapper(ShoppingList, lists, properties={ + 'entries': db.relationship( + ListEntry, + back_populates='shoppingList', + cascade='all, delete-orphan', + ) + })