Skip to content

Commit f74cfdf

Browse files
periercCharles Perier
and
Charles Perier
authored
fix: error when adding child to node with no children (#447)
Co-authored-by: Charles Perier <[email protected]>
1 parent 7180f5c commit f74cfdf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

backend/editor/entries.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -613,12 +613,12 @@ async def update_node_children(self, entry, new_children_ids):
613613
for child_id in children_ids:
614614
# Create new relationships if it doesn't exist
615615
query = f"""
616-
MATCH ()-[r:is_child_of]->(parent:{self.project_name}:ENTRY),
617-
(new_child:{self.project_name}:ENTRY)
616+
MATCH (parent:{self.project_name}:ENTRY), (new_child:{self.project_name}:ENTRY)
618617
WHERE parent.id = $id AND new_child.id = $child_id
618+
OPTIONAL MATCH ()-[r:is_child_of]->(parent)
619619
WITH parent, new_child, COUNT(r) AS rel_count
620620
MERGE (new_child)-[r:is_child_of]->(parent)
621-
ON CREATE SET r.position = rel_count
621+
ON CREATE SET r.position = CASE WHEN rel_count IS NULL THEN 1 ELSE rel_count + 1 END
622622
"""
623623
_result = await get_current_transaction().run(
624624
query, {"id": entry, "child_id": child_id}

0 commit comments

Comments
 (0)