I'm trying to make a query to get some data from my database but I can't seem to figure out how.
My database looks like this:
_User
| objectId | username | password | groups (relation(group_name)) | .. |
Group
| objectId | group_name | .. |
Activity
| objectId | activity_name | groups (pointer(objectId)) | .. |
My goal is to show all the activities the current user (logged in) is linked to. So a user can be part of a group (relation), and a group can have multiple activities. The activities have a pointer to Group.objectId. How can I show the activities of the group that the current user is a member of?
Currently this is my code:
ParseObject current = ParseUser.getCurrentUser();
ParseRelation relation = current.getRelation("groups");
ParseQuery query = relation.getQuery();
ParseObject test = new ParseObject("group");
String ObjectId = test.getObjectId();
ParseQuery<ParseObject> query2 = new ParseQuery<ParseObject>("Activity");
query2.whereEqualTo("group_name", ObjectId);
..
@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listview);
// Pass the results into an ArrayAdapter
adapter = new ArrayAdapter<String>(MainActivity.this, R.layout.activity_main_listview_item);
// Retrieve object "name" from Parse.com database
for (ParseObject query : ob) {
adapter.add((String) query.get("activity_name"));
}
The answer is in the Parse Guide: