简体   繁体   English

在对象化中使用'IN'查询

[英]Using 'IN' query in objectify

How do I use 'IN' query in objectify? 如何在objectify中使用“ IN”查询? I have a 'Paper' entity and a different entity 'Schedule'. 我有一个“纸”实体和一个不同的“时间表”实体。 In 'Schedule' I have key of paper. 在“计划”中,我有纸质钥匙。 Now I get a few keys of 'Paper' using some criteria. 现在,我使用一些条件获得了一些“ Paper”键。 Now I want to filter those with 'scheduledDate'. 现在,我想用“ scheduledDate”过滤那些。 I want to query 'Schedule' with something like this: get 'schedule' from 'Schedule' where 'paper key' in (List of paper keys) and 'scheduledDate' = 'some date' . 我想用类似这样的查询'Schedule': get 'schedule' from 'Schedule' where 'paper key' in (List of paper keys) and 'scheduledDate' = 'some date' How do I do this in objectify? 我如何客观地做到这一点? Thanks 谢谢

Objectify is a thin wrapper around low-level Datastore API, so IN operator behaves the same as the low-level API: Objectify是低层数据存储区API的精简包装,因此IN运算符的行为与低层API相同:

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

This assumes that your Schedule class has a field List<Key> paper that contains list of keys pointing to Paper entities (you could also have List<Key<Paper>> paper if you use objectify's type-safe Key s). 这假设您的Schedule类具有一个字段List<Key> paper ,该字段包含指向Paper实体的键的列表(如果使用objectify的类型安全Key则也可以具有List<Key<Paper>> paper )。

Note how IN performs a series of queries under the hood and combines result. 注意IN如何IN执行一系列查询并组合结果。 So in a sense it behaves as a series of "=" operators whose result is merged: 因此,从某种意义上讲,它表现为一系列“ =”运算符,其结果被合并:

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM