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

Fixes #277 relationship match return node set #642

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions neomodel/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@ def __init__(self, source):
self.source_class = source
elif isinstance(source, StructuredNode):
self.source_class = source.__class__
elif isinstance(source, NodeSet):
self.source_class = source.source_class
self.source = source.source
else:
raise ValueError("Bad source for nodeset " + repr(source))

Expand Down Expand Up @@ -783,19 +786,19 @@ def __init__(self, source, name, definition):
self.name = name
self.filters = []

def match(self, **kwargs):
def match(self, **kwargs) -> NodeSet:
"""
Traverse relationships with properties matching the given parameters.

e.g: `.match(price__lt=10)`

:param kwargs: see `NodeSet.filter()` for syntax
:return: self
:return: NodeSet
"""
if kwargs:
if self.definition.get('model') is None:
raise ValueError("match() with filter only available on relationships with a model")
output = process_filter_args(self.definition['model'], kwargs)
if output:
self.filters.append(output)
return self
return NodeSet(self)
6 changes: 3 additions & 3 deletions neomodel/relationship_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ def single(self):
except IndexError:
pass

def match(self, **kwargs):
def match(self, **kwargs) -> NodeSet:
"""
Return set of nodes who's relationship properties match supplied args
Return set of nodes whose relationship properties match supplied args

:param kwargs: same syntax as `NodeSet.filter()`
:return: NodeSet
:return: NodeSet of the resulting traversal
"""
return self._new_traversal().match(**kwargs)

Expand Down
18 changes: 18 additions & 0 deletions test/test_issue277.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from neomodel import StructuredNode, StructuredRel, StringProperty, UniqueIdProperty, RelationshipTo, NodeSet


class SomeRel(StructuredRel):
prop = StringProperty()


class SomeNode(StructuredNode):
identifier = UniqueIdProperty()

connected_to = RelationshipTo('SomeNode', 'CONNECTED', model=SomeRel)


def test_rel_match_returns_node_set():
a = SomeNode()
a.save()

assert type(a.connected_to.match(prop="asdf")) is NodeSet