Maz*_*yod 0 python google-app-engine app-engine-ndb google-cloud-datastore
在我正在开发的GAE应用程序中,我有一个Room实体,它有KeyProperty一个Match对象.房间应该总是匹配,没有房间就不能存在匹配.
现在,我假设我必须创建一个这样的匹配对象:
Match(parent=room.key)
Run Code Online (Sandbox Code Playgroud)
但是,房间总是要求创建匹配,我想到这样做的唯一方法如下:
room = Room()
match = Match(parent=room.put())
room.match_key = match.put()
room.put() # again!
Run Code Online (Sandbox Code Playgroud)
有没有办法避免这个问题?
我不明白为什么你希望Match都将Room作为父级,而父级要将KeyProperty用于Match.这是不必要的循环.选择一个或另一个:如果您想要父/子关系,请保留父键并查询Match via ancestor(); 否则遗漏父键,所以不需要先创建Room.