簡體   English   中英

NDB多對多KeyProperty類引用不起作用

[英]NDB many-to-many KeyProperty kind reference not working

我正在嘗試使用App Engine中的KeyProperties將各種實體彼此鏈接:

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中的種類分配就很好了,一切都可以運行了。 不過,我需要循環引用它們,並且看起來應該可以。

難道我做錯了什么?

在這種情況下,可以將類型作為字符串傳遞:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM