java - How to fetch nested child entities using parent entity key using datastore api -


here i'm using datastore api create, update & retrieve entities.

my use case is, have child , grand child entities of parent entity.

my entity structure follows:

 company      --> employee             --> address (multiple address entities). 

here have company entity key , need fetch employee details along address entities configured employee.

example:

company --> aaa      employee --> john                    address --> california                   address --> redwood      employee --> robert                   address --> new york                   address --> washington 

my query follows:

datastoreservice datastore = datastoreservicefactory.getdatastoreservice();  query query = new query("employee").setancestor(companykey); datastore.prepare(query).aslist(fetchoptions.builder.withdefaults()); 

my required result should employee entities of john & robert along respective address entities.

appengine documentation says:

public query setancestor(key ancestor)

"sets ancestor query. restricts query return result entities descended given entity. in other words, of results have ancestor parent, or parent's parent, or etc. if null specified, unsets previously-set ancestor. passing null parameter not query entities without ancestors (this type of query not supported)."

so code should work fine. return entities aaa ancestor i.e; both employee (parent) , address (parent's parent) entities.

documentation link


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -