Issue
I have a table of users in parse.com
where each of them contains fields first_name and last_name. I'm doing user search and cannot figure out how to make condition OR.
My example:
ParseRelation<ParseUser> relation = user.getRelation("Friends");
ParseQuery<ParseUser> query = relation.getQuery();
query.whereContains("first_name", "typed text"); //need to add OR for the same condition,
//but for the field "last_name"
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> objects, ParseException e) {
if(e == null){
//doing work
}else {
e.printStackTrace();
}
}
});
I tried to do this way:
query.whereContains("first_name", "typed text").whereContains("last_name", "typed text");
but no, it's searching for satisfying both conditions.
Method whereContainsAll()
is applicable for list
of values, but not keys.
I can do it by sending 2 requests, but this is horrible solution. Is there a way we can do that?
Solution
You can use ParseQuery.or(queries) Here is the docs link: https://parse.com/docs/android/guide#queries-compound-queries
Updated 08-2022:
https://docs.parseplatform.org/android/guide/#compound-queries
Example code from doc:
ParseQuery<ParseObject> lotsOfWins = ParseQuery.getQuery("Player");
lotsOfWins.whereGreaterThan(150);
ParseQuery<ParseObject> fewWins = ParseQuery.getQuery("Player");
fewWins.whereLessThan(5);
List<ParseQuery<ParseObject>> queries = new ArrayList<ParseQuery<ParseObject>>();
queries.add(lotsOfWins);
queries.add(fewWins);
ParseQuery<ParseObject> mainQuery = ParseQuery.or(queries);
mainQuery.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> results, ParseException e) {
// results has the list of players that win a lot or haven't won much.
}
});
Answered By - Norutan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.