【发布时间】:2017-05-11 19:37:26
【问题描述】:
tldr:我可以在 Datastore 投影查询中执行此操作吗?
keyProjectionQuery = Conferences.query( \
key=ndb.Key(Conferences, RegistrationId), \
projection=[Conferences.allConferences])
详细说明: 考虑以下情况,其中 Student 实体是 Conferences 实体的祖先。
- 学生类中的每个学生只有一个会议类实体。
-
Conferences.allConferences 将学生参加的每个会议都作为重复领域举行。
班级学生(ndb.model):
RegistrationId = ndb.StringProperty() Name = ndb.StringProperty()类会议(ndb.model):
allConferences = ndb.StringProperty(repeated=True)class StudentsForm(messages.message):
Name = messages.StringField(1) RegistrationId = messages.StringField(2)class ConferencesForm(messages.message):
allConferences = messages.StringField(1, repeated=True)
我有一个基于祖先键获取 Conferences.allConferences 的投影查询:-
ancestorProjQuery = Conferences.query( \
ancestor=ndb.Key(Students, RegistrationId), \
projection=[Conferences.allConferences])
我可以在投影查询中使用会议键吗?像这样?
keyProjQuery = Conferences.query( \
key=ndb.Key(Conferences, RegistrationId), \
projection=[Conferences.allConferences])
我试过了,但我得到一个错误:
TypeError: __init__() got an unexpected keyword argument 'key'
第三种选择当然是从 Conferences 中获取整个实体并仅返回 allConferences 属性。
AllConferences = ndb.Key(Conferences, RegistrationId).get()
另外,哪一个会更便宜?
我对 Python、Datastore 和 App Engine 非常陌生。
【问题讨论】:
标签: python-2.7 google-app-engine google-cloud-datastore