Mani
Mani

Reputation: 1

Parse Android - Query multiple tables

I have 2 tables in Parse:

Post
name (string)
user (pointer to a User table)
group (pointer to a Group table) i.e. post belongs to a group

Vote
yes (boolean)
no (boolean)
user (pointer to a User table)
post (pointer to the Post table above)

I need to display all votes that belong to a particular post. I have done this as follows:

ParseQuery<ParseObject> posts = ParseQuery.getQuery("Post");
posts.include("Group");
posts.whereEqualTo("group", ParseObject.createWithoutData("Group",  
gObjId));

ParseQuery<ParseObject> votes = ParseQuery.getQuery("Vote");
votes.include("Post");
votes.whereMatchesKeyInQuery("post","objectId", posts);

All the above works. What I have a massive issue with is I now want to access fields from both post and vote tables. I can access the fields in the vote table easily but how do I access anything in the post table. This is the code I have:

        votes.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> objects, ParseException e) {

                if (e == null) {
                    if (objects.size() > 0) {
                        for (ParseObject vote : objects) {
                            //Trying to access the name field in post but its not working 
                            chatHistory.add(vote.getParseObject("post").getString("name"));
                        }
                        chatList.setAdapter(adapter);
                    } else {
                        Toast.makeText(getApplicationContext(), "Empty", Toast.LENGTH_LONG).show();
                    }

                } else {
                    Log.i("Error", e.getMessage());
                }
            }
        });

Upvotes: 0

Views: 218

Answers (1)

Thesoham24
Thesoham24

Reputation: 194

why don't you execute separate query for it:

posts.findInBackgroun

Upvotes: 0

Related Questions