On Tue, Jan 26, 2010 at 4:40 PM, Jeff Schnitzer <j...@infohazard.org> wrote:
>
> If you want to ask "what albums are this photo in?" (equivalent to
> "what messages are waiting for me" in the video), you query like this:
>
> OQuery<PhotoIndex> query =
> createQuery(PhotoIndex.class).filter("photos", photoKey);
> List<OKey<Album>> keys = ofy.prepareKeysOnly(query).asList();
> List<Album> albums = ofy.get(keys);

I made a mistake here - you need to grab the parents of the keys.  So
the full process is:

OQuery<PhotoIndex> query =
createQuery(PhotoIndex.class).filter("photos", photoKey);

List<OKey<Album>> albumKeys = new ArrayList<OKey<Album>>();
for (OKey<PhotoIndex> indexKey: ofy.prepareKeysOnly(query).asIterable())
    albumKeys.add(indexKey.getParent());

List<Album> albums = ofy.get(albumKeys);

We're making some API changes in v2 which will make this a little prettier.

Jeff

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to