Using Parse.com and javaScript SDK.
I've got the following query. I need it to return results for both
query.equalTo("fromUser", currentUser);
query.equalTo("toUser", currentUser);
As per below it can only return either or, not both. How do I concatenate these too make it work with both?
Do I do one query then nest another below it? or is there a better approach?
var currentUser = Parse.User.current();
var FriendRequest = Parse.Object.extend("FriendRequest");
var query = new Parse.Query(FriendRequest);
query.include('toUser');
query.include('SentTo');
query.include("myBadge");
query.equalTo("fromUser", currentUser);
query.equalTo("toUser", currentUser);
query.equalTo("status", "Connected");
query.find({
What you can use is the Parse.Query.or
function.
var currentUser = Parse.User.current();
var FriendRequest = Parse.Object.extend("FriendRequest");
var queryOne = new Parse.Query(FriendRequest);
queryOne.equalTo("fromUser", currentUser);
var queryTwo = new Parse.Query(FriendRequest);
queryTwo.equalTo("toUser", currentUser);
var mainQuery = Parse.Query.or(queryOne, queryTwo);
mainQuery.equalTo("status", "Connected");
mainQuery.find({ /* ... */ });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.