4

objectify で「IN」クエリを使用するにはどうすればよいですか? 「紙」エンティティと別のエンティティ「スケジュール」があります。「スケジュール」には紙の鍵があります。ここで、いくつかの基準を使用して「Paper」のキーをいくつか取得します。ここで、「scheduledDate」でそれらをフィルタリングしたいと思います。次のようなもので「Schedule」を照会したい: get 'schedule' from 'Schedule' where 'paper key' in (List of paper keys) and 'scheduledDate' = 'some date'. objectify でこれを行うにはどうすればよいですか? ありがとう

4

1 に答える 1

6

Objectify は低レベルの Datastore API の薄いラッパーであるため、IN 演算子は低レベル API と同じように動作します。

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

これは、エンティティを指すキーのリストを含むScheduleフィールドがクラスにあることを前提としています( objectify のタイプ セーフs を使用する場合もある可能性があります)。List<Key> paperPaperList<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 に答える