GO VEGAN
GO VEGAN

Reputation: 1143

parse.com - > how to do "or" between constraints

I want to do the foloowing:

query.equalTo("m_user_send", user.get("username"));  or
query.equalTo("m_user_get", user.get("username"));  

pay attention that it is differnt from the exmaple:

// Finds scores from any of Jonathan, Dario, or Shawn
query.containedIn("playerName",
                  ["Jonathan Walsh", "Dario Wunsch", "Shawn Simon"]);   

Upvotes: 3

Views: 1264

Answers (1)

bobbyrehm
bobbyrehm

Reputation: 446

You can accomplish this by creating multiple queries and then combining them using Parse.Query.or() :

var query1 = new Parse.Query("MyClass");
query1.equalTo("m_user_send", user.get("username"));
var query2 = new Parse.Query("MyClass");
query2.equalTo("m_user_get", user.get("username"));

var orQuery = new Parse.Query.or(query1, query2);
orQuery.find().then(function(results) {
    //returns all objects that match either query1 or query2
});

See http://parse.com/docs/js/symbols/Parse.Query.html for further documentation.

Upvotes: 6

Related Questions