0

我尝试各种实体KeyProperties App Engine中像这样的相互链接:NDB许多一对多KeyProperty一种参考不工作

class ModelA(ndb.Model): 
    mod_bs = ndb.KeyProperty(kind=ModelB, repeated=true) 
    mod_cs = ndb.KeyProperty(kind=ModelC, repeated=true) 
    # other properties 

class ModelB(ndb.Model): 
    mod_as = ndb.StringProperty(kind=ModelA, repeated=true) 
    mod_cs = ndb.StringProperty(kind=ModelC, repeated=true) 
    # other properties 

class ModelC(ndb.Model): 
    mod_cs = ndb.KeyProperty(kind=ModelA, repeated=true) 
    mod_as = ndb.KeyProperty(kind=ModelB, repeated=true) 
    # other properties 

,但我得到一个错误,指出“ModelB”在这个结构中是未定义的。显然,任何下面定义的地方都不能被识别。因此,如果我摆脱了ModelA和ModelB中的类似任务,那么ModelC中的那些任务都可以正常工作。不过,我需要循环引用它们,而且似乎应该起作用。

我做错了什么?

回答

1

在这种情况下,你可以通过那种作为一个字符串:

class ModelA(ndb.Model): 
    mod_bs = ndb.KeyProperty(kind='ModelB', repeated=true) 
    mod_cs = ndb.KeyProperty(kind='ModelC', repeated=true) 
    # other properties