对于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());


非常感谢您提供的任何帮助!

最佳答案

因为您的put(..)语句不包含grandbabyPhoto,所以不会保存它。

07-24 13:24