Katedral Pillon
Katedral Pillon

Reputation: 14864

objectify query by keys

I have an Entity as

@Entity
public class Book{
  ...
  List<Key<Page>> pages;
  ...
}

So to get a book I do

Book book = ofy().load().type(Book.class).id(id).now();

Having obtained the book, I want to get the pages; hence my question: can I query by keys or must I query by ids? If I had the ids I could do

List<Page> pages = ofy().load().type(Page.class).ids(ids);

But what I need is

List<Page> pages = ofy().load().type(Page.class).keys(keys);

otherwise I have to do linear work to iterate through the keys to extract the ids or the names, which I am not even sure will work because the keys actually have parents so that a key for a page is constructed as

Key pageKey = KeyFactory.createKey(bookKey, Page.class.getSimpleName(),someString);

So what is my final answer in this case?

Upvotes: 0

Views: 1052

Answers (1)

tj-recess
tj-recess

Reputation: 1809

You can easily load entities by Keys. From ofy's Concepts page (https://code.google.com/p/objectify-appengine/wiki/Concepts)

Map<Key<Object>, Object> lotsOfThings = ofy().load().keys(carKey, airplaneKey, chairKey, personKey, yourMamaKey);

Upvotes: 1

Related Questions