【问题标题】:Relationship to nodes of different types in neomodelneomodel中与不同类型节点的关系
【发布时间】:2015-12-10 09:14:16
【问题描述】:

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

我需要类似的东西

rel = RelationshipTo('NodeTypeOne|NodeTypeTwo', 'REL');

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

【问题讨论】:

    标签: django neo4j neomodel


    【解决方案1】:

    尝试在您定义的类中将关系拆分为两个关系声明:

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

    一个简单的例子:

    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)
    

    我们最终会得到n3n1n2 具有相同关系名称REL 的连接。这是最终结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多