按"键"过滤物体对象查询领域

时间:2015-10-15 23:43:37

标签: google-app-engine filter google-cloud-endpoints google-cloud-datastore objectify

我有以下Objectify关系:

@Entity(“Author”)
public class Author{
  @Id
  private long authorId;
  …

}

@Entity(“Book”)
public class Book{
  @Id
  private long id;
  private Key<Author> authorKey;
  …

}

现在有趣的部分:我有authorId(id,而不是实体),我需要为该作者查询Book。我的查询如下,但它返回一个空列表,而我知道这个作者在数据存储区中有书。那么我该如何解决这个问题?

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

2 个答案:

答案 0 :(得分:3)

您需要Book.authorKey Book.date var tiledImage = Task.Factory.ContinueWhenAll( images, (i) => TileImages(i)); // We are currently on the UI thread. Save the sync context and pass it to // the next task so that it can access the UI control "image1". var UISyncContext = TaskScheduler.FromCurrentSynchronizationContext(); // On the UI thread, put the bytes into a bitmap and // and display it in the Image control. var t3 = tiledImage.ContinueWith((antecedent) => { ... ... }, UISyncContext); 字段。如果这需要{authorKey,date}上的多属性索引,我无法记得,但是请不要尝试,看看它是否有效。

我还建议您拨打电话&#39;作者&#39;不是&#39; authorKey&#39;。

答案 1 :(得分:1)

您正在查询字段authorId,而不是您刚刚创建的authorKey

OfyService.ofy().load().type(Book.class).filter("authorKey", authorKey).order(“-date").list();

通过此更改和索引,您应该得到结果。