我正在使用 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
是设计使然还是错误?我看到以前使用命名空间时出现了一些与 get_by_id() 相关的问题(我使用的是 SDK 1.6.6)。我怎样才能文件夹有来自 id 的父母?