0
votes

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;
   ...
}
2
In what way is it 'failing'? Is it throwing an exception or is it not returning entities that you know for a fact are in the database? Something else?Adam Crossland
Adding to what Adam said: can you post a snippet of your code where you execute the query and a stack trace (if "failing" is an exception)alex
There is no failure. The code is not returning any result. I'm doing the test with GQL directly in prod.Jordi P.S.
Please include the exact GQL you are executing - there is almost certainly something wrong in the formulation of the query.stickfigure
SELECT * FROM Room WHERE ANCESTOR IS Key('Site',1) does not work and SELECT *WHERE ANCESTOR IS Key('Site',1) does not return any Room either.Jordi P.S.

2 Answers

2
votes

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

0
votes

Problem solved:

The issue was when creating C the parent key was incorrectly created. The parent key for C was K(B) and it is supposed to be K(A,B) always containing the parent.

It is like that so the entity group can be referenced. A reference to A is needed since there is only one entity group despite the nesting.