[英]How can I query for root entities in the App Engine DataStore (Java)
I'm trying to write a query which will identify and return all root entities (ie 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: 我最初尝试调用
Query.setAncestor(null)
但后来从数据存储区Query文档中发现这无效:
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).
将NULL作为参数传递给Query.setAncestor(String ancestor)不会查询没有祖先的实体(当前不支持此类型的查询)。
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. 因此,由于查询API所包含的内容,我现在有些困惑,我无法弄清楚如何构造一个可以识别所有根实体的查询。
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 :-) 这需要是应用程序的功能,因此我正在寻找一种能够以编程方式工作的解决方案,而不是一些手动干预。wnich要求我登录到管理控制台并单击一个按钮:-)
Anyone know how to do this? 有人知道怎么做吗?
Cheers, 干杯,
Edd 埃德
You will need to add a property to your models that you can query on. 您将需要在模型中添加一个属性,以供查询。 Perhaps a boolean named
is_root
or something similar. 可能是一个名为
is_root
的布尔值或类似名称。
As the documentation indicates, there's no way to do this - other than working around it as @Robert suggests. 如文档所示,除了按照@Robert的建议进行处理之外,没有其他方法可以这样做。 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.
如果您告诉我们您正在努力实现的目标-与您正在努力实现的目标相对-也许我们可以就如何最好地实现它提供建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.