1

Really struggling with this query, all I want to do is run a query through my Routines table selecting Routines that belong to a certain user. Running a normal query would require something query.whereEqualTo("routineIcon", "1") would bring up the the first and third row. However, the tricky bit is querying the user (Point<_user>) field, this is a reference to a user (objectId) from the User class. Initially I tried query.whereEqualTo("user", "RE1bvmzyPk"), but this came out blank so I looked into querying Pointers, I've trie d a few things but can't get it to work. Anyone got any tips?

private void retrieveRoutines() {
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Routine");
    query.whereEqualTo("user", "RE1bvmzyPk");
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> routines, ParseException e) {
            if (e==null){
                mRoutines = routines;
                String[] routineNames = new String[mRoutines.size()];
                int i = 0;
                for (ParseObject routine : mRoutines) {
                    routineNames[i] = routine.getString("routineName");
                    Log.d("OK", routineNames[i]);
                    i++;
                }


            }

            else {
                //error
            }
        }
    });
}

The Routine Class is in the format:

objectId (string) | routineIcon (string) | routinesName (string) | user (Pointer<_User>

2 Answers 2

5

You can create the user pointer by using the objectid of the user

ParseUser user=new ParseUser();
user.setObjectId("RE1bvmzyPk");

ParseQuery<ParseObject> query = ParseQuery.getQuery("Routine");
query.whereEqualTo("user", user);
query.findInBackground(new FindCallback<ParseObject>() {
    @Override
    public void done(List<ParseObject> routines, ParseException e) {
        if (e==null){



        }

        else {
            //error
        }
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

if you want routines that point back to ( were created by a User )

Add the pointer field to Routines:

"createdBy" type=pointer

And then query for it using the User Obj.

  ParseQuery<ParseObject> query = ParseQuery.getQuery("Routine");
    query.whereEqualTo("createdBy", $userObj);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.