Rahul
Rahul

Reputation: 1627

Unable to OR two condition in Parse query

I have been trying to OR two condition on two different fields of a table. while individual condition works fine, but when I try to use it both, it doesn't work. Here is my code :

ParseQuery<NewExamAlert> query = ABC.getQuery();
query.whereContainedIn("category", Arrays.asList(arr)); //here arr is array of different category
query.whereContainedIn("subCategory", Arrays.asList(arr1));//here arr1 is array of different subcategory
query.findInBackground(new FindCallback<ABC>() {
            public void done(List<ABC> list, ParseException exp) {
                //My Logic
            }
}

Please let me know, what am I missing ?

Upvotes: 0

Views: 310

Answers (1)

323go
323go

Reputation: 14274

You'll need to explicitly "or" them:

List<ParseQuery<NewExamAlert>> queries = new ArrayList<ParseQuery<NewExamAlert>>();
queries.add( ParseQuery<NewExamAlert> query1 = ABC.getQuery()
                 .whereContainedIn("category", Arrays.asList(arr)) );
queries.add( ParseQuery<NewExamAlert> query2 = ABC.getQuery()
                 .whereContainedIn("subCategory", Arrays.asList(arr1)) );

ParseQuery<NewExamAlert> orQuery = ParseQuery.or( queries );

orQuery.findInBackground(new FindCallback<ABC>() {
            public void done(List<ABC> list, ParseException exp) {
                //Your Logic
            }
}

Upvotes: 2

Related Questions