1
我很明顯地對GAE祖先查詢應該如何工作感到困惑。我的理解是,祖先查詢應該返回所有後代,而不僅僅是直接的孩子。但是,如果我按照以下方式修改開發者指南中的示例,則只會檢索直接子項,而不會檢索孫子。我錯過了什麼?谷歌應用程序引擎祖先查詢
Entity person = new Entity("Person", "tom");
Entity weddingPhoto = new Entity("Photo", person.getKey());
weddingPhoto.setProperty("imageUrl",
"http://domain.com/some/path/to/wedding_photo.jpg");
Entity babyPhoto = new Entity("Photo", person.getKey());
babyPhoto.setProperty("imageUrl",
"http://domain.com/some/path/to/baby_photo.jpg");
//添加這個孫子:
Entity grandbabyPhoto = new Entity("Photo", babyPhoto.getKey());
grandbabyPhoto.setProperty("imageUrl",
"http://domain.com/some/path/to/grandbabyPhoto.jpg");
Entity dancePhoto = new Entity("Photo", person.getKey());
dancePhoto.setProperty("imageUrl",
"http://domain.com/some/path/to/dance_photo.jpg");
Entity campingPhoto = new Entity("Photo");
campingPhoto.setProperty("imageUrl",
"http://domain.com/some/path/to/camping_photo.jpg");
getDatastore().put(
java.util.Arrays.asList(person, weddingPhoto, babyPhoto, dancePhoto, campingPhoto));
Query userPhotosQuery = new Query("Photo");
userPhotosQuery.setAncestor(person.getKey());
// This returns weddingPhoto, babyPhoto and dancePhoto, but
// not grandbabyPhoto --- why???
List<Entity> results =
getDatastore().prepare(userPhotosQuery).asList(
FetchOptions.Builder.withDefaults());
非常感謝任何幫助,您可以提供!
顯然,@ peter。謝謝。令人驚訝的是你如何看和看不到。 –