Reputation: 89
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:
Upvotes: 0
Views: 767
Reputation: 6289
not sure that you could do the following with 2 queries...
Get a set of groups for the currentUser as a queryResult $myGroupQ the set of groups that a user belongs to
Query 2 using "query.include("groups")
Query 2 is query.Activity with Condition:
query.whereContainedIn("groups", $myGroup);
as long as var myGroup is ofType=Array, this should work.
so using the $myGroup from qry1 as the constraint setOfValues in query #2's "containedIn"
from the android docs section on query constraints
Upvotes: 0