gpt4 book ai didi

python - py2neo ogm incoming related is None,为什么?

转载 作者:太空宇宙 更新时间:2023-11-04 05:11:28 24 4
gpt4 key购买 nike

当我想使用 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 映射获取传入关系。这是一个错误吗?或者我 ?感谢您的帮助。

最佳答案

我找到了解决方案,关系名称必须相同,相关属性不够。

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>]

关于python - py2neo ogm incoming related is None,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42897807/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com