我正在使用 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 Neo4j self 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28267810/