How can I make Parse.Query.AND?

2019-09-14 14:24发布

问题:

I need to connect 2 queries in Parse.com with an and, my code is:

    var queryDeseo1 = new Parse.Query(DeseosModel);
    queryDeseo1.equalTo("User", Parse.User.current());
    queryDeseo1.equalTo("Deseo", artist);

    queryDeseo1.find({...

The result of the .find is all the objects with User = Parse.User.current()) and all the objects with Deseo = artist but I want the objects with the two queries together:

User = Parse.User.current()) and Deseo = artist

回答1:

You've actually got it setup correctly to do an AND query. The problem (assuming that your data structure is setup properly) is that your User field is a Pointer to the User table. Therefore, you need to query for a User equal to the pointer, as opposed to a User equal to Parse.User.current() which will return a string. Something like the following:

var userPointer = {
  __type:    'Pointer',
  className: 'User',
  objectId:  Parse.User.current().id
}

queryDeseo1.equalTo('User', userPointer);