2017-04-04 46 views
0

我有幾個約束條件的查詢:如何使用ParseQuery對同一個數據庫列執行OR查詢?

ParseQuery <ParseObject> requestsQuery = ParseQuery.getQuery(ParseConstantsUtil.CLASS_REQUEST); 
requestsQuery.whereContains(ParseConstantsUtil.REQUEST_AUTHOR, currentUser.getObjectId()); 
requestsQuery.whereEqualTo(ParseConstantsUtil.REQUEST_STATUS, "Approved"); 
requestsQuery.whereEqualTo(ParseConstantsUtil.REQUEST_STATUS, "Rejected"); 
requestsQuery.whereEqualTo(ParseConstantsUtil.REQUEST_READ, false); 
try { 
List <ParseObject> requestsList = requestsQuery.find(); 
return listSize(model, requestsList); 
} catch (ParseException e) { 
e.printStackTrace(); 
} 

其中的一個制約因素髮生在我的數據庫中有關同一列:

requestsQuery.whereEqualTo(ParseConstantsUtil.REQUEST_STATUS, "Approved"); 
requestsQuery.whereEqualTo(ParseConstantsUtil.REQUEST_STATUS, "Rejected"); 

上面似乎並沒有工作。我如何使用ParseQuery對同一個數據庫列進行OR查詢?

requestsQuery.whereEqualTo(ParseConstantsUtil.REQUEST_STATUS, "Rejected" || "Approved"); 
+0

[Multiple Combined「或」使用Android分析的查詢「的可能重複(http://stackoverflow.com/questions/28892973/multiple-combined-or-queries-using-android-parse) – john16384

回答

1

使用ParseQuery#whereContainedIn

List<String> vals = new ArrayList<>(); 
vals.add("Rejected"); 
vals.add("Approved"); 
requestsQuery.whereContainedIn((ParseConstantsUtil.REQUEST_STATUS, vals); 

更多信息請參見api documentation

相關問題