如何按祖先检索 Google App Engine 实体
我的 Google App Engine 数据存储区中有以下 2 个模型:
class Search(db.Model):
what = db.StringProperty()
class SearchResult(db.Model):
search = db.ReferenceProperty(Search)
title = db.StringProperty()
content = db.StringProperty()
并且,我尝试在以下函数中检索给定搜索实体的所有 SearchResult 实体:
def get_previous_search_results(what='', where=''):
search_results = None
search = db.GqlQuery("SELECT * FROM Search WHERE what = :1", what).fetch(1)
if search:
search_results = db.GqlQuery("SELECT * FROM SearchResult WHERE ANCESTOR IS :1", search[0].key()).fetch(10)
return search_results
但是,它始终返回一个空集。
有什么想法我做错了吗?我已通读 Python Datastore API 文档,这看起来像是执行此操作的正确方法,但它不起作用。
I have the following 2 models in my Google App Engine datastore:
class Search(db.Model):
what = db.StringProperty()
class SearchResult(db.Model):
search = db.ReferenceProperty(Search)
title = db.StringProperty()
content = db.StringProperty()
And, I am trying to retrieve all SearchResult entities for a given Search entity in the following function:
def get_previous_search_results(what='', where=''):
search_results = None
search = db.GqlQuery("SELECT * FROM Search WHERE what = :1", what).fetch(1)
if search:
search_results = db.GqlQuery("SELECT * FROM SearchResult WHERE ANCESTOR IS :1", search[0].key()).fetch(10)
return search_results
However, it always returns an empty set.
Any ideas what I am doing wrong? I've read through the Python Datastore API docs and this seem like the correct way to do this, but it's not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否与父级一起创建搜索实体? ReferenceProperty 不会创建祖先关系,并且您可能需要 search.searchresult_set,它将是对具有对搜索对象“search”的引用的 SearchResult 对象的查询。
Are you creating the Search entities with a parent? The ReferenceProperty doesn't create an ancestor relationship, and it seems likely you might want search.searchresult_set, which will be a Query for SearchResult objects that have a reference to the Search object 'search'.