gpt4 book ai didi

python - 新开发银行 : How to use get_by_id for entities in an entity group

转载 作者:太空狗 更新时间:2023-10-30 02:22:22 26 4
gpt4 key购买 nike

我正在使用 get_by_id() 从 NDB 读取实体,但我无法让它为属于实体组的实体工作:

from google.appengine.ext import ndb

class Folder(ndb.Model):
name = ndb.StringProperty()

parent_folder_key = Folder(name = 'Parent folder').put()
sub_folder_key = Folder(name = 'Subfolder', parent=parent_folder_key).put()

id_list = []
print 'All folders:'
for f in Folder.query():
print f
id_list.append(f.key.id())

print '\nFolders by id:'
for id in id_list:
print Folder.get_by_id(id)

输出:

All folders:
Folder(key=Key('Folder', 5814), name=u'Parent folder')
Folder(key=Key('Folder', 5814, 'Folder', 5815), name=u'Subfolder')

Folders by id:
Folder(key=Key('Folder', 5814), name=u'Parent folder')
None

是设计使然还是错误?我看到有 been some issues以前使用 namespace 时与 get_by_id() 有关(我使用的是 SDK 1.6.6)。我怎样才能从 id 中找到具有父级的文件夹?

最佳答案

get_by_id(id, parent=None) 采用父参数。
当您在实体组中按 id 查询时,您必须包含父键才能获得所需的实体。

https://developers.google.com/appengine/docs/python/ndb/modelclass#Model_get_by_id

关于python - 新开发银行 : How to use get_by_id for entities in an entity group,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11051029/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com