Parse.com request for pointer value
I am using Parse.com for my android app database.
In short, I am asking for class A that has a field pointing to class B. If I query for class A and include class B, is there anyway I can have a query filter and / or sort by field in class B?
I am more familiar with sql style db, which may become apparent from my description. In the parse I have a table for people invited to the game "gameInvitees" with some metadata like when they were invited and their rsvp status. Then a separate table with games "gameInstances". The "gameInvitees" has a pointer to the game they are invited to and the invited parsing user.
My problem is that I am trying to query the "gameInvitees" table so that I can find new users invited to the game based on the game time that is in the "gameInstance" table.
My current code looks something like this:
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.HOUR, -1);
final Date oneHourBack = cal.getTime();
// get games that the current user is invited to
ParseQuery<GamePhaseInvitees> inviteeQuery = ParseQuery.getQuery("gameInvitees");
inviteeQuery.whereEqualTo("inviteeAccount", ParseUser.getCurrentUser()); // current user is invited
inviteeQuery.include("GameInstance");
// inviteeQuery.whereGreaterThanOrEqualTo("GameInstance.GameTime", oneHourBack); // game is one hour back (but, this doesn't work)
inviteeQuery.findInBackground(new FindCallback<GamePhaseInvitees>() {
public void done(List<GamePhaseInvitees> gamesInvitedToList, ParseException e) {
if (e == null) {
} else {
}
}
});
This code has been simplified to explain the problem. Basically I need to figure out what I can do with this commented line in order to query the field that is associated with the pointer. Is it possible? Are there any solutions to solve this problem?
Here's a possible solution:
Create a ParseObject from your table type: ParseObject time = new ParseObject("Date");
Then take ParseObject from the result:time = result.getParseObject(pointer_field);
Now you can get from time
any field, which it has, as you did, for example time.getString("some_field")
.
You may also need to include: query.include("pointer_field")
.
According to the Parse community:
Instead of dot notation in whereKey :, you must use whereKey: matchesKey: inQuery: or whereKey: matchesQuery :.