0

I have Conversation classes with a members relation attribute pointing to User class.

This members attribute consists of people belong to a particular conversation.

Now I want to query if given array of pointers User is part of particular conversation given that all elements must match.

I tried to use containsAll("members", users) but instead got undefined. containedIn() worked but it returned all matching conversation that has at least one matching User in array. equalTo("members", users) was not working as well and note that the users variable is array of pointers and not just array of strings objectId, but I also tried that one but got me nowhere.

Here's what I tried: * Created AND queries where userRelationQuery.equalTo('member', ParseUser1) up to N number of users and still didn't work

Here's my solution but feel free to correct this for improvement

const members = getMembers();

let query = new Parse.Query("Conversation").equalTo(
 "members",
 members[0]
);

for (let i = 0; i < members.length; i++) {
 query = new Parse.Query("Conversation")
   .matchesKeyInQuery("objectId", "objectId", query)
   .equalTo(
     "members",
     members[i]
   );
}

const chat = await query.includeAll().first();
4
  • Hi! Are you still facing this error? Commented Apr 17, 2019 at 13:31
  • Yes, I still stick to my solution though... Commented Apr 17, 2019 at 14:28
  • Can you please paste here the content of the variable members? Commented Apr 18, 2019 at 11:35
  • members is just a relation of _User Commented Apr 19, 2019 at 16:19

1 Answer 1

0

This should work for you

var conversationClass = Parse.Object.extend('Conversation');
var conversationQuery = new Parse.Query(conversationClass);
return conversationQuery.first()
    .then(queryResult => {
        var userRelationQuery = queryResult.relation('members').query(); //You can get all users releated to this conversation
        //userRelationQuery.equalTo('username', 'Blank0330') // Or you can add more conditions
        return userRelationQuery.find()
            .then(users => {
                return users; //This is your releated users
            });
    });

For more information about Parse-JS-SDK Relation

Sign up to request clarification or add additional context in comments.

1 Comment

See my solution above. I want to check if given N number of users are all members of particular conversation and get it. I tried creating AND queries where userRelationQuery.equalTo("members", ParseUser{N}) but still didn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.