py2neo ogm传入相关是无,为什么?

时间:2017-03-20 07:17:24

标签: python neo4j py2neo

当我想从具有py2neo ogm的节点获取传入关系时,我遇到了麻烦。这是一个例子:

class A1(GraphObject):
    rFrom = RelatedFrom("A2", "A2")

class A2(GraphObject):
    rTo = RelatedTo("A1", "A1")

a1 = A1()
a2 = A2()
a2.rTo.add(a1)

GRAPH.push(a2)

n_a1 =  list(A1.select(GRAPH))[0]
n_a2 =  list(A2.select(GRAPH))[0]

print list(n_a1.rFrom)
print list(n_a2.rTo)

[]
[<A1 __id__=1006>]

所以,我不明白如何获得与ogm映射的传入关系。 这是一个错误吗?或者我 ? 谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

我找到了解决方案,关系名称必须相同,相关的属性并不是一致的。

class A1(GraphObject):
    rFrom = RelatedFrom("A2", "LINK")

class A2(GraphObject):
    rTo = RelatedTo("A1", "LINK")

a1 = A1()
a2 = A2()
a2.rTo.add(a1)

GRAPH.push(a2)

n_a1 =  list(A1.select(GRAPH))[0]
n_a2 =  list(A2.select(GRAPH))[0]

print list(n_a1.rFrom)
print list(n_a2.rTo)

[<A2 __id__=1007>]
[<A1 __id__=1006>]