In my Conversation
classes, there is a members
relation attribute that points to the User
class.
The members
attribute contains the people who belong to a specific conversation.
I am trying to query whether a given array of User
pointers is part of a particular conversation, ensuring that all elements must match.
Although I attempted to use containsAll("members", users)
, it resulted in undefined
.
containedIn()
did work, but it returned all conversations with at least one matching User
in the array.
equalTo("members", users)
also did not work, even when the users
variable is an array of pointers and not just an array of objectId
strings. I even tried the latter with no success.
My attempt involved creating AND queries with
userRelationQuery.equalTo('member', ParseUser1)
for each user, up to N number of users, but it still did not work.
Below is my solution, but I am open to any corrections 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();