与neomodel中不同类型节点的关系

时间:2015-08-24 07:34:51

标签: django neo4j neomodel

我可以与不同类型的节点建立关系吗?

我需要像

这样的东西
rel = RelationshipTo('NodeTypeOne|NodeTypeTwo', 'REL');

rel = RelationshipTo('StructuredNode', 'REL');

1 个答案:

答案 0 :(得分:0)

Try splitting the relationship into two relationship declarations, within the class you defined:

rel1 = RelationshipTo('NodetypeOne', 'REL')
rel2 = RelationshipTo('NodetypeTwo', 'REL')

A quick example:

class NodeType1(StructuredNode):
    name = StringProperty()

class NodeType2(StructuredNode):
    name = StringProperty()

class NodeType3( StructuredNode ):
    name = StringProperty()

    rel1 = RelationshipTo( 'NodeType1', 'REL')
    rel2 = RelationshipTo( 'NodeType2', 'REL')

n1 = NodeType1(name='nodetype1').save()
n2 = NodeType2(name='nodetype2').save()
n3 = NodeType3(name='nodetype3').save()
n3.rel1.connect(n1)
n3.rel2.connect(n2)

We'll end up with n3 having connections to n1 and n2 with the same relationship name REL. Here's the end result:

enter image description here