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 (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 conta开发者_如何学运维ins 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
You will need to add a property to your models that you can query on. Perhaps a boolean named is_root
or something similar.
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.
精彩评论