Datastore ancestor filters

62 views
Skip to first unread message

Louise Elmose Hedegaard

unread,
Mar 17, 2016, 11:31:14 AM3/17/16
to Google App Engine
Hi,

I am trying to use ancestor filters, but it does not work as I expect it to.

I have a shop entity with an id generated by the datastore.
I have an order entity with an id I set myself, and the parent of the order is the shop.
I have a transaction entity with an id I set myself, and the parent of the transaction is the order.

Now I would like to get the transactions which has a given shop ancestor, so I set the ancestor on the transaction query like this:

query.setAncestor(KeyFactory.createKey("shop", shop.getId()));

where shop.getId() is a string, i.e. the key name.

But when I execute the query I do not get any results.
Did I misunderstod how ancestor filters are to be used?

When I create orders I can see the parent is set to the shop as expected, when I create transactions I can see the parent is set to the shop as expected.
But when I have a transaction entity and call transaction.getParent().getParent() I would expect to get the shop, but I get null.

Thanks,
-Louise

Nick (Cloud Platform Support)

unread,
Mar 18, 2016, 2:10:52 PM3/18/16
to Google App Engine
Hey Louise,

The specific details required to diagnose this specific issue are not provided, so it's difficult to reason about the issue. And while I'm happy to assist, I feel I should take a moment to emphasize that this is a specific technical issue, and not so much a general discussion on the platform which will be useful or informative to other users. Posts like this are better suited to Stack Overflow (we monitor there as well, so not to worry), and if you were to post there, the following information would give the highest chance of a good reply:

* The definitions of the entities
* The code which creates / inserts the entities
* The code which retrieves the entities

With those details, potential issues in the entity relations or in the query, or in the code even, could be diagnosed.

Best wishes,

Nick
Cloud Platform Community Support
Reply all
Reply to author
Forward
0 new messages