2012-08-12 50 views
3

如何在对象化中使用'IN'查询?我有一个'纸'实体和一个不同的实体'计划'。在'时间表'中,我有纸的钥匙。现在我使用一些标准来获取“纸张”的几个键。现在我想用'scheduledDate'过滤那些。我想用这样的查询'Schedule':get 'schedule' from 'Schedule' where 'paper key' in (List of paper keys) and 'scheduledDate' = 'some date'。我如何在客观化中做到这一点?由于在对象化中使用'IN'查询

回答

6

客体是一种简单包装的低级别的数据存储API,所以在操作者的行为一样的低级别的API:

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

这是假设你的Schedule类具有包含列表字段List<Key> paper指向Paper实体的键(如果您使用物体的类型安全的Key s,也可以有List<Key<Paper>> paper)。

请注意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.