1

我正在使用来自https://github.com/robinedwards/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

如何实现自引用模型?任何信息都会非常有帮助,在此先感谢!

4

1 回答 1

3

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

于 2015-02-02T10:54:48.187 回答