Skip to content

Commit

Permalink
Fix #589 match relationship with same name as source and target nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Conjeaud committed Sep 26, 2023
1 parent 5c501a6 commit bfa75f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 5 additions & 4 deletions neomodel/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion test/test_match_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit bfa75f6

Please sign in to comment.