Reputation: 89
I'm trying to make a query to get certain objects. The thing is.. I don't know how to make a query to get object that match an array. The User can be a member of multiple Groups, so the names of these groups are stored in User.groups as an array. I am trying to get all the objects of the class 'Group' that the current user is a member of. I came up with this:
ParseQuery query1 = ParseQuery.getQuery("_User"); //selects User Class
query1.whereEqualTo("username", current_user.toString()); //selects current user
query1.include("groups"); //include 'groups' of type array with names of the groups that the user is a member of
ParseQuery query2 = ParseQuery.getQuery("Group"); //select Groups Class
query2.whereContainedIn("group_name", ?); //<-- Get objects where group_name matches a value in the User.groups
The last line of code is obviously not the way to do it. I already looked at the Parse Guide! Help is much appreciated!
Upvotes: 0
Views: 347
Reputation: 89
After some digging and testing I came up with a solution. It wasn't that difficult actually..
ParseQuery<ParseObject> groupQuery = new ParseQuery<ParseObject> ("Group");
groupQuery.include("array");
groupQuery.whereEqualTo("array", ParseUser.getCurrentUser().getUsername());
This code selects the class 'Group' which has an array with all the usernames in it called 'members' that looks like: ["user1","user2",".."]. This array is included. The last line of code selects all the objects that the user is a member of.
Upvotes: 1