Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Multiple Combined Or Queries using Android Parse Android

    • 0
    • 1
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 455
    Comment on it

    To implement "OR" feature on the query we need to merge two queries.

    First, create a list of queries and add the queries that you want to implement.

    And then ParseQuery.or() methods to make a final query.

    Below is the code

     ParseQuery myQuery1 = new ParseQuery("Chatting");
            myQuery1.whereEqualTo("sender_name", ParseUser.getCurrentUser().getString("name"));
    
            ParseQuery myQuery2 = new ParseQuery("Chatting");
            myQuery2.whereEqualTo("receiver_name", ParseUser.getCurrentUser().getString("name"));
    
    
            List<ParseQuery<ParseObject>> queries = new ArrayList<ParseQuery<ParseObject>>();
            queries.add(myQuery1);
            queries.add(myQuery2);
            ParseQuery<ParseObject> query = ParseQuery.or(queries);
    
    
            query.addAscendingOrder("createdAt");
    
    
    query.findInBackground(new FindCallback<ParseObject>() {
                public void done(List<ParseObject> chatList, ParseException e) {
                    if (e == null) {
                       Toast.makeText(ChatActivity.this, "Done!!!", Toast.LENGTH_LONG).show();
    
    
                    } else {
    
                        Toast.makeText(getAplicationContext(), "Error : "+e.getMessage(), Toast.LENGTH_LONG).show();
    
                    }
                }
            });
    

 1 Comment(s)

  • Very Nice blog on parse, specially for "or conditions" implementation. I was stuck using parse PHP SDK to find out the records from User table where search value can be available in any defined fields. I took guidance from this blog and implemented it in PHP, following is my code.

                    $condition1 = new ParseQuery("_User");
                    $condition1->startsWith("email", $searchText);
    
                    $condition2 = new ParseQuery("_User");
                    $condition2->startsWith("definedUsername", $searchText);
    
                    $condition3 = new ParseQuery("_User");
                    $condition3->startsWith("name", $searchText);
    
                    $combinedConditions = array();
                    array_push($combinedConditions, $condition1,$condition2,$condition3);
    
                    $finalQuery = new ParseQuery("_User");
                    $combineQuery = $finalQuery->orQueries($combinedConditions);
                    $results = $combineQuery->find();
    
    
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: