Dridia
Dridia

Reputation: 183

use specific value from ParseObject to a new query

I'm trying to get the value relatedGuild from ParseObject relationShipObject that has been sent to another method.

My code:

private void getRelation(){
    Log.i("Status:", "Retrieving current user...");
    //Retrieve the current logged in user
    ParseUser currentUser = ParseUser.getCurrentUser();

    Log.i("Status:", "Retrieving relationship...");
    //Retrieve the relationship object for currentUser
    ParseQuery<ParseObject> relationQuery = ParseQuery.getQuery("relation");
    query.whereEqualTo("relatedUser", currentUser);
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> relationShip, ParseException e) {
            if (e == null) {
                for (ParseObject relationShipObject : relationShip) {
                    // This does not require a network access.
                    relationshipObject.get("relatedGuild");
                    getGuild(relationShipObject);
                }
            } else {
                Log.d("relation", "Error: " + e.getMessage());
            }
        }
    });
}
private void getGuild(ParseObject relationShipObject){
    Log.d("relation", "relationShipObject:" + relationShipObject.getString("relatedGuild"));
}

When i call Log.d in method getGuild i get a value equal to null. Am I trying to retrieve the value from row relatedGuild the wrong way? If yes, do you have any solution to the problem?

Update: When i change from getString to get("relatedGuild").toString(), i get a value that looks like this: com.parse.ParseObject@21u702b7. That means relationShipObjectcontains some kind of value i don't know how to retrieve.

Upvotes: 1

Views: 103

Answers (1)

Marius Waldal
Marius Waldal

Reputation: 9952

Try this:

private void getRelation(){
    Log.i("Status:", "Retrieving current user...");
    //Retrieve the current logged in user
    ParseUser currentUser = ParseUser.getCurrentUser();

    Log.i("Status:", "Retrieving relationship...");
    //Retrieve the relationship object for currentUser
    ParseQuery<ParseObject> relationQuery = ParseQuery.getQuery("relation");
    query.whereEqualTo("relatedUser", currentUser);
    query.include("relatedGuild");  // <-THIS INCLUDES THE OBJECT BEHIND THE POINTER
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> relationShip, ParseException e) {
            if (e == null) {
                for (ParseObject relationShipObject : relationShip) {
                    // This does not require a network access.
                    relationshipObject.get("relatedGuild");
                    getGuild(relationShipObject);
                }
            } else {
                Log.d("relation", "Error: " + e.getMessage());
            }
        }
    });
}
private void getGuild(ParseObject relationShipObject){
    Log.d("relation", "relationShipObject:" + relationShipObject.getString("relatedGuild"));
}

Upvotes: 1

Related Questions