2012-08-12 71 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.