From f74cfdf7f01fa2814b0772ec701eeedab52d6dce Mon Sep 17 00:00:00 2001 From: Charles Perier <82757576+perierc@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:00:35 +0100 Subject: [PATCH] fix: error when adding child to node with no children (#447) Co-authored-by: Charles Perier --- backend/editor/entries.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/editor/entries.py b/backend/editor/entries.py index d6c84fa5..857d7fdc 100644 --- a/backend/editor/entries.py +++ b/backend/editor/entries.py @@ -613,12 +613,12 @@ async def update_node_children(self, entry, new_children_ids): for child_id in children_ids: # Create new relationships if it doesn't exist query = f""" - MATCH ()-[r:is_child_of]->(parent:{self.project_name}:ENTRY), - (new_child:{self.project_name}:ENTRY) + MATCH (parent:{self.project_name}:ENTRY), (new_child:{self.project_name}:ENTRY) WHERE parent.id = $id AND new_child.id = $child_id + OPTIONAL MATCH ()-[r:is_child_of]->(parent) WITH parent, new_child, COUNT(r) AS rel_count MERGE (new_child)-[r:is_child_of]->(parent) - ON CREATE SET r.position = rel_count + ON CREATE SET r.position = CASE WHEN rel_count IS NULL THEN 1 ELSE rel_count + 1 END """ _result = await get_current_transaction().run( query, {"id": entry, "child_id": child_id}