如何查询 App Engine DataStore (Java) 中的根实体
我正在尝试编写一个查询,该查询将识别并返回所有根实体(即没有祖先的实体)。我最初尝试调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要向模型添加一个可以查询的属性。也许是一个名为
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.正如文档所示,除了按照 @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.