简体   繁体   中英

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

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM