From bfa75f69cb561bd3fdcddadbdc9d6b7cecf375da Mon Sep 17 00:00:00 2001 From: Marius Conjeaud Date: Tue, 26 Sep 2023 16:10:27 +0200 Subject: [PATCH] Fix #589 match relationship with same name as source and target nodes --- neomodel/match.py | 9 +++++---- test/test_match_api.py | 13 ++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/neomodel/match.py b/neomodel/match.py index 24c47c33..20a4bb92 100644 --- a/neomodel/match.py +++ b/neomodel/match.py @@ -422,12 +422,13 @@ def build_traversal(self, traversal): rhs_label = ":" + traversal.target_class.__label__ # build source + rel_ident = self.create_ident() lhs_ident = self.build_source(traversal.source) - rhs_ident = traversal.name + rhs_label - self._ast.return_clause = traversal.name + traversal_ident = f"{traversal.name}_{rel_ident}" + rhs_ident = traversal_ident + rhs_label + self._ast.return_clause = traversal_ident self._ast.result_class = traversal.target_class - rel_ident = self.create_ident() stmt = _rel_helper( lhs=lhs_ident, rhs=rhs_ident, @@ -439,7 +440,7 @@ def build_traversal(self, traversal): if traversal.filters: self.build_where_stmt(rel_ident, traversal.filters) - return traversal.name + return traversal_ident def _additional_return(self, name): if name not in self._ast.additional_return and name != self._ast.return_clause: diff --git a/test/test_match_api.py b/test/test_match_api.py index af9e2ea5..f7e94995 100644 --- a/test/test_match_api.py +++ b/test/test_match_api.py @@ -41,6 +41,10 @@ class Coffee(StructuredNode): id_ = IntegerProperty() +class Extension(StructuredNode): + extension = RelationshipTo("Extension", "extension") + + def test_filter_exclude_via_labels(): Coffee(name="Java", price=99).save() @@ -111,7 +115,7 @@ def test_simple_traverse_with_filter(): assert qb._ast.lookup assert qb._ast.match - assert qb._ast.return_clause == "suppliers" + assert qb._ast.return_clause.startswith("suppliers") assert len(results) == 1 assert results[0].name == "Sainsburys" @@ -180,6 +184,13 @@ def test_issue_208(): assert len(b.suppliers.match(courier="dhl")) +def test_issue_589(): + node1 = Extension().save() + node2 = Extension().save() + node1.extension.connect(node2) + assert node2 in node1.extension.all() + + def test_contains(): expensive = Coffee(price=1000, name="Pricey").save() asda = Coffee(name="Asda", price=1).save()