I’m using nested entity groups in an HRD google app engine datastore.
A < B < C considering X < Y means that X is parent of Y
Are all C in the same entity group (A one) ?
I want to query all the C which have the same parent A. How would I do it?
This is failing:
SELECT * FROM C WHERE ANCESTOR IS Key(‘A’,1)
Any tip?
The test has been done directly in GQL in the datastore, regardless, I attach the snippet of code (Ofy4 code):
That is A:
@Entity
@Cache
public class Site implements Serializable {
private static final long serialVersionUID = 8611281648072797702L;
@Id
private Long id;
private String url;
...
}
That is B:
@Entity
@Cache
public class Accom implements Serializable, HasCapacity {
@Id
private Long id;
@Parent
private Key<Site> site;
...
}
That is C:
@Entity
@Cache
public class Room implements Serializable, HasCapacity {
@Id
private Long id;
@Parent
private Key<Accom> accom;
...
}
According to the google documentation this should work.
and http://code.google.com/appengine/docs/python/datastore/queries.html
Ancestor Queries
You can filter your datastore queries to a specified ancestor, so that results contain only entities containing that ancestor. In other words, all of the results will have the ancestor as their parent, or parent’s parent, or etc. Passing None as a parameter does not query for entities without ancestors and will return errors.
Other links with useful info:
http://code.google.com/appengine/docs/python/datastore/gqlreference.html#Examples
http://code.google.com/appengine/docs/python/datastore/entities.html