Skip to content

Commit

Permalink
fix: error when adding child to node with no children (#447)
Browse files Browse the repository at this point in the history
Co-authored-by: Charles Perier <[email protected]>
  • Loading branch information
perierc and Charles Perier authored Mar 14, 2024
1 parent 7180f5c commit f74cfdf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/editor/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit f74cfdf

Please sign in to comment.