Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error when adding child to node with no children #447

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/editor/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,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
Loading