Skip to content

Commit

Permalink
SCKAN-373 fix: Add missing service file
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Dec 17, 2024
1 parent 9d48c2e commit 46ef27c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions backend/composer/services/layers_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.db import transaction



def update_from_entities_on_deletion(connectivity_statement, deleted_entity_id):
"""
Updates the 'from_entities' for Layers that used the deleted entity.
Scoped to the given ConnectivityStatement.
"""
from composer.models import Destination, Via

# Filter affected layers within the same ConnectivityStatement
affected_via_layers = Via.objects.filter(
connectivity_statement=connectivity_statement,
from_entities__id=deleted_entity_id
)

affected_destination_layers = Destination.objects.filter(
connectivity_statement=connectivity_statement,
from_entities__id=deleted_entity_id
)

# Update 'from_entities' by removing the deleted entity
for via in affected_via_layers:
via.from_entities.remove(deleted_entity_id)

for destination in affected_destination_layers:
destination.from_entities.remove(deleted_entity_id)

0 comments on commit 46ef27c

Please sign in to comment.