Skip to content

Commit

Permalink
Fixed OGM scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
technige committed Aug 18, 2020
1 parent 16ef700 commit ba5a822
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion py2neo/ogm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ def __init__(self, object_class, repository):
def match(self, primary_value=None):
cls = self._object_class
if cls.__primarykey__ == "__id__":
match = NodeMatcher.match(self, cls.__primarylabel__).where("id(_) = %d" % primary_value)
match = NodeMatcher.match(self, cls.__primarylabel__)
if primary_value is not None:
match = match.where("id(_) = %d" % primary_value)
elif primary_value is None:
match = NodeMatcher.match(self, cls.__primarylabel__)
else:
Expand Down
7 changes: 7 additions & 0 deletions test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ def graph(uri):
return Graph(uri)


@fixture(scope="function")
def repo(graph):
graph.delete_all()
yield Repository.wrap(graph)
graph.delete_all()


@fixture(scope="function")
def movie_graph(graph):
graph.delete_all()
Expand Down
7 changes: 7 additions & 0 deletions test/integration/test_ogm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def test_simple_push(graph):
assert thing.__node__.identity is not None


def test_simple_match_with_no_id(repo):
repo.save(SimpleThing())
thing = repo.match(SimpleThing).first()
assert thing.__node__.graph is repo.graph
assert thing.__node__.identity is not None


class A(Model):

b = RelatedTo("B")
Expand Down

0 comments on commit ba5a822

Please sign in to comment.