我正在使用https://github.com/robinedwards/neomodel中的neomodel库。文档http://neomodel.readthedocs.org/en/latest/

我有2个实体和类别类-每个类别都属于一个实体,每个实体都可以具有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


如何实现自我参照模型?任何信息将非常有帮助,谢谢!

最佳答案

这是因为此时尚未编译Entity类。如果将其更改为字符串“ Entity”,则应可以正常工作。

关于python - Python Neo4j自我引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28267810/

10-11 10:55