Reputation: 57
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>
Upvotes: 1
Views: 2034
Reputation: 466
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
}
}
});
Upvotes: 5
Reputation: 6289
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);
Upvotes: 0