【发布时间】:2019-12-14 13:35:39
【问题描述】:
我有一个 Google App 引擎 NDB 的实体,它有一个重复的 KeyProperty,我想在元素列表上使用“包含 AND”进行查询。
我指的是这里列出的“解决方案2”:How to query with a list object on repeated string property in ndb,问题是我不知道查询列表有多少元素。
这是我的模型:
class Record(ndb.Expando):
name = ndb.StringProperty(required=True)
ref = ndb.KeyProperty(Client, repeated=True)
以及我的查询尝试:
q = Record.query()
for client in getlist('ref[]'):
q.filter(Record.ref == ndb.Key(urlsafe=client))
或
q.filter(Record.ref == [ndb.Key(urlsafe=elem) for elem in getlist('ref[]')])
我认为在重复属性上实现包含和查询的最佳方法是使用ndb.AND 运算符,如https://cloud.google.com/appengine/docs/standard/python/ndb/queries#nest_and_or 和上面提到的 SO 响应中,但我需要用未知数字“组合”它元素...ndb.AND(kind.prop==elem_1, kind.prop==elem_2, ...kind.prop==elem_N).
【问题讨论】:
标签: python google-app-engine app-engine-ndb