Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine Datastore: How to get entity by ID/Name if parent key is unknown?

Tags:

There are two kinds of entity: User and Trip. User is parent to Trip and Trip is child to User.

For privacy consideration I am POSTing only Trip ID/Name. Because it is looks like a Trip Key contains encoded User ID/Name.

How to get entity by ID/Name if parent key is unknown?

like image 491
Kappa Leonis Avatar asked Jan 13 '13 08:01

Kappa Leonis


2 Answers

You can't. Parent key is part of the entity key and you need a full key to get an entity.

Also query with key filter won't find entities with parents unless you specify the ancestor key.

like image 54
Peter Knego Avatar answered Sep 18 '22 20:09

Peter Knego


If you create all of your "User" entities under a "Root" entity and add a "uuid" property to your "Trip" entity, you can look for the single "Trip" with the specified UUID.

Filter uuidFilter = new FilterPredicate("uuid", FilterOperator.EQUAL, uuid.toString()); Query q = new Query("Trip").setAncestor(root.getKey()).setFilter(uuidFilter); 
like image 25
vharron Avatar answered Sep 20 '22 20:09

vharron