如何查询 App Engine DataStore (Java) 中的根实体

发布于 2024-11-27 20:09:07 字数 491 浏览 0 评论 0原文

我正在尝试编写一个查询,该查询将识别并返回所有根实体(即没有祖先的实体)。我最初尝试调用 Query.setAncestor(null),但后来从 数据存储查询文档表明这不起作用:

将 null 作为参数传递给 Query.setAncestor(Stringancestor) 不会查询没有祖先的实体(当前不支持此类查询)。

所以现在我有点卡住了,考虑到查询 API 包含的内容,我无法弄清楚如何构建一个识别所有根实体的查询。

这需要成为应用程序功能,因此我正在寻找一种以编程方式工作的解决方案,而不是需要我登录管理控制台并单击按钮的手动干预:-)

有人知道如何做到这一点吗?

干杯,

艾德

I'm trying to write a query which will identify and return all root entities (i.e. entities which have no ancestor). I initially tried calling Query.setAncestor(null) but later found out from the datastore Query docs that this doesn't work:

Passing null as a parameter to Query.setAncestor(String ancestor) does not query for entities without ancestors (this type of query is not currently supported).

So now I'm a bit stuck, given what the Query API contains I can't figure out how one would construct a query which identified all the root entities.

This needs to be app functionality so I'm looking for a solution which works programatically as opposed to some manual intervention wnich requires me to log in to the admin console and click a button :-)

Anyone know how to do this?

Cheers,

Edd

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

↙厌世 2024-12-04 20:09:07

您需要向模型添加一个可以查询的属性。也许是一个名为 is_root 的布尔值或类似的值。

You will need to add a property to your models that you can query on. Perhaps a boolean named is_root or something similar.

猫腻 2024-12-04 20:09:07

正如文档所示,除了按照 @Robert 建议解决它之外,没有办法做到这一点。如果您告诉我们您想要实现什么目标 - 而不是您如何实现它 - 也许我们可以提供有关如何最好地实现它的建议。

As the documentation indicates, there's no way to do this - other than working around it as @Robert suggests. If you tell us what you're trying to achieve - as opposed to how you're trying to achieve it - perhaps we can provide a suggestion on how best to go about it.

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