我显然对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());
非常感谢您提供的任何帮助!
答案 0 :(得分:1)
由于您的put(..)
语句不包含grandbabyPhoto
,因此无法保存。