如何按祖先检索 Google App Engine 实体

发布于 2024-08-29 08:22:48 字数 847 浏览 9 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纸短情长 2024-09-05 08:22:48

您是否与父级一起创建搜索实体? 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'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文