【问题标题】:Python Neo4j Self referencePython Neo4j 自我参考
【发布时间】:2015-02-02 18:54:48
【问题描述】:

我正在使用来自 https://github.com/robinedwards/neomodel 的新模型库。文档http://neomodel.readthedocs.org/en/latest/

我有 2 个类 Entity 和 Category - 每个 Category 属于一个 Entity,每个 Entity 都可以有一个 parent_entity。对于类别类,这是有效的:

class Category(StructuredNode):
    name = StringProperty(required=True)
    entity = RelationshipTo(Entity, 'BELONGS_TO', cardinality=One)
    created_at = DateTimeProperty()
    updated_at = DateTimeProperty()

但是对于我写的实体类:

class Entity(StructuredNode):
    name = StringProperty(required=True)
    image = StringProperty()
    description = StringProperty()
    parent_entity = Relationship(Entity, 'PARENT', cardinality=ZeroOrMore)
    categories = RelationshipFrom(Category, 'BELONGS_TO', cardinality=ZeroOrMore)
    created_at = DateTimeProperty()
    updated_at = DateTimeProperty()

这给了我一个错误,上面写着:

parent_entity = Relationship(Entity, 'PARENT', cardinality=ZeroOrMore)
NameError: name 'Entity' is not defined

如何实现自引用模型?任何信息都会非常有帮助,提前谢谢!

【问题讨论】:

    标签: python neo4j neomodel


    【解决方案1】:

    这是因为此时实体类还没有被编译。如果将其更改为字符串“实体”,它应该可以按预期工作。

    【讨论】:

      猜你喜欢
      • 2017-02-13
      • 1970-01-01
      • 2014-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 2020-09-19
      • 2020-07-26
      相关资源
      最近更新 更多