add relationship

This commit is contained in:
2025-09-23 11:36:07 -03:00
parent 18674d8831
commit 9c38e68a34
3 changed files with 44 additions and 7 deletions

View File

@@ -73,15 +73,34 @@ def enroll(
}
)
for entity in linked_entities:
keyprefix = entity.type.lower()
# Relationships between this enrollment and its related entities
for parent_entity in linked_entities:
perent_id = parent_entity.id
entity_sk = f'LINKED_ENTITIES#{parent_entity.type}'
keyprefix = parent_entity.type.lower()
# Child knows the parent
transact.put(
item={
'id': enrollment.id,
'sk': f'LINKED_ENTITIES#{entity.type}',
'sk': entity_sk,
'kind': 'PARENT',
'created_at': now_,
f'{keyprefix}_id': entity.id,
}
f'{keyprefix}_id': perent_id,
},
cond_expr='attribute_not_exists(sk)',
)
# Parent knows the child
transact.put(
item={
'id': perent_id,
'sk': entity_sk,
'kind': 'CHILD',
'created_at': now_,
f'{keyprefix}_id': enrollment.id,
},
cond_expr='attribute_not_exists(sk)',
)
if org: