如何在 Google App Engine 中查询 属性 的 属性?
How to query the property of a property in Google App Engine?
我有两个 NDB 模型 类,书籍和作者。 Author 有一个 StringProperty "name" 和一个 auto_add_now "date",Book 有一个 PickleProperty "authors",它是 Author 类型的对象列表。
我想查询并接收作者列表中包含 currentAuthor 的所有图书的列表(匹配 "name" 并忽略 "date")。我不认为我可以直接使用 .IN,因为日期可能不同。为了测试目的,我正在设置 date=None(因为对于所有 Author 对象来说,它似乎都是 None?这是因为我在本地 运行 吗?)然后写作
books = Book.query(Book.authors.IN([currentAuthor])).fetch()
但是 returns 一个空列表。
它不适用于 PickleProperty
来自文档
PickleProperty - Value is a Python object (such as a list or a dict or a string) that
is serializable using Python's pickle protocol; the Datastore stores
the pickle serialization as a blob. Unindexed by default.
即使您确实将其编入索引,您也不会实现 IN 查询,因为它不知道已将 pickle 中的实体编入索引作为单独的索引值。
您应该为作者使用重复的 StructuredProperty、KeyProperty 或 StringProperty。然后您可以按预期执行查询。
我有两个 NDB 模型 类,书籍和作者。 Author 有一个 StringProperty "name" 和一个 auto_add_now "date",Book 有一个 PickleProperty "authors",它是 Author 类型的对象列表。
我想查询并接收作者列表中包含 currentAuthor 的所有图书的列表(匹配 "name" 并忽略 "date")。我不认为我可以直接使用 .IN,因为日期可能不同。为了测试目的,我正在设置 date=None(因为对于所有 Author 对象来说,它似乎都是 None?这是因为我在本地 运行 吗?)然后写作
books = Book.query(Book.authors.IN([currentAuthor])).fetch()
但是 returns 一个空列表。
它不适用于 PickleProperty
来自文档
PickleProperty - Value is a Python object (such as a list or a dict or a string) that is serializable using Python's pickle protocol; the Datastore stores the pickle serialization as a blob. Unindexed by default.
即使您确实将其编入索引,您也不会实现 IN 查询,因为它不知道已将 pickle 中的实体编入索引作为单独的索引值。
您应该为作者使用重复的 StructuredProperty、KeyProperty 或 StringProperty。然后您可以按预期执行查询。