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

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

4

1 回答 1

1

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

于 2012-06-01T23:25:19.833 回答