开发者

app engine query filter by 'id' range of entities, ignoring ancestor(s)

开发者 https://www.devze.com 2023-03-26 18:04 出处:网络
I have entities like these ones: Entity [products(147)] Entity [manufacturer(23)/products(131)] Entity [manufacturer(17)/products(131)]

I have entities like these ones:

Entity [products(147)]

Entity [manufacturer(23)/products(131)]

Entity [manufacturer(17)/products(131)]

Now, I'm trying to find using a Query all the entities of kind 'products' which have an ID from 100 and up. Ones like the above 147 & 131.

The problem is that I don't know how to ask for these, "detaching" the ancestor from it in the query.

Tried these:

Not working:

SELECT __key__ FROM products WHERE ID >= 100

Partially working:

SELECT __key__ FROM products WHERE __key__ >= 100

This is how I insert the query filter:

query.addFilter("__key__",开发者_如何学编程 FilterOperator.GREATER_THAN_OR_EQUAL, KeyFactory.createKey("products", 100));

This partially working one gives the proper results ONLY for 'root' entities, i.e ones without an ancestor.

Any way to modify it so it ignore ancestor(s)? Thanks!


There's no built in way to do this, because this query is meaningless. IDs are allocated such that they are unique for a given kind and parent. You can't rely on IDs alone to uniquely identify an entity if it might have different parent entities, so it's pretty meaningless to query for a range of IDs regardless of parent.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号