4

如何在 objectify 中使用“IN”查询?我有一个“Paper”实体和一个不同的实体“Schedule”。在“时间表”中,我有纸键。现在我使用一些标准得到了一些“纸”键。现在我想用'scheduledDate'过滤那些。我想用这样的东西查询“计划”:get 'schedule' from 'Schedule' where 'paper key' in (List of paper keys) and 'scheduledDate' = 'some date'。我如何在客观化中做到这一点?谢谢

4

1 回答 1

6

Objectify 是低级 Datastore API 的精简包装器,因此 IN 运算符的行为与低级 API 相同:

ofy.query(Schedule.class).filter("paper IN", listOfPaperKeys).filter("scheduledDate = ", someDate)

这假设您的Schedule类有一个List<Key> paper包含指向实体的键列表的字段(如果您使用 objectify 的 type-safe s Paper,您也可以拥有)。List<Key<Paper>> paperKey

请注意如何IN在后台执行一系列查询并组合结果。所以从某种意义上说,它表现为一系列“=”运算符,其结果被合并:

The IN operator also performs multiple queries, one for each item in the 
specified list, with all other filters the same and the IN filter replaced with
an EQUAL filter. The results are merged, in the order of the items in the list. 
If a query has more than one IN filter, it is performed as multiple queries, 
one for each possible combination of values in the IN lists.
于 2012-08-12T19:47:57.017 回答