Search code examples
javascriptparse-platformparse-server

parse server: exclude relation from query javascript sdk


i am trying to query a class of users which contains a relation column called "blocking" which contains a list of user objects from the same class

when i try to query all users i would like to query which is not present in this relation column

i did the following

var currentUser = Parse.User.current();
var relation = currentUser.relation('blocking')
query.doesNotExist(relation);
query.find().then((users)=>{
  for (let i = 0; i < users.length; i++) {
    let object = users[i];
    console.log(object)

  }
  }, (error) => {
    console.log(error);
  });

but it did not work

any help will be appreciated


Solution

  • I managed to do it myself

    at first i query the relation and store a list of blocked ids in an array

        var currentUser = Parse.User.current();
          var relation = currentUser.relation("blocking");
          relation.query().find().then(blockedusers=>{
            var blockedIds = []
            for (var i = 0; i<blockedusers.length; i++){
              blockedIds.push(blockedusers[i].id)
            } 
          })
    

    after that i moved the whole query inside the relation find and do (not contained in) this array like the following

             query.notContainedIn("objectId", blockedIds)
    

    that solved my problem

    thanks