I have the following Objectify relationship:
@Entity(“Author”)
public class Author{
@Id
private long authorId;
…
}
@Entity(“Book”)
public class Book{
@Id
private long id;
private Key<Author> authorKey;
…
}
Now for the fun part: I have the authorId (the id, not entity) and I need to query Book for that author. My query is below, but it is returning an empty list, whereas I know for a fact that this author has books in the datastore. So how might I fix this query?
public static List<Book> getBooksForAuthor(Long authorId) {
Key<Author> authorKey = Key.create(Author.class, authorId);
return OfyService.ofy().load().type(Book.class).filter("authorKey", authorKey).order(“-date").list();
}