0

I'm using Parse.com for my android apps database.

In short I'm querying class A that has a field pointing to class B. If I query class A and include class B is there anyway I can have the query filter and/or sort by a field in class B?

I'm more familiar with sql style db as may become obvious from my description. In parse I have a table for the people invited to a game "gameInvitees" with some metadata such as when they were invited and their rsvp status. Then a separate table with the games "gameInstances". The "gameInvitees" include a pointer to the game they are invited to and the parse user that is invited.

My issue is I'm trying to query the "gameInvitees" table so that I can find current users invited to a game based on the game time, which 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 {
            }

        }
    });

That code is simplified a bit to explain the problem. Basically I need to figure out something I can do with that commented out line to query on a field that is connected by a pointer. Is that possible? Are there any clean workaround solutions for that?

2
  • What does your log show as your error? One potential problem I can envision is that Calendar.getInstance is created in your app and not in the database, so the database might have a slightly different time (potentially off by a few miliseconds). Commented Sep 14, 2014 at 1:51
  • I think the problem is with the commented out line. When I uncomment it I get Dot notation can only be used on objects. I've tried it with just "gameTime" but, that returns no results I assume without the dot notation the condition is being applied to the wrong table. So really I'm just trying to figure out how I can make a conditional query for an object that is attached by a pointer. Is that possible? The database table is fine though Commented Sep 14, 2014 at 3:07

2 Answers 2

1

Here is a possible solution:

Create a ParseObject from the type of your table: ParseObject time = new ParseObject("Date"); Then get the ParseObject from the result: time = result.getParseObject(pointer_field);

Now you can pull from time any field that it has just as you would do it normally, for example: time.getString("some_field").

You may also need to include: query.include("pointer_field").

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response. I don't think I was quite clear on my issue. In short I'm querying class A that has a field pointing to class B. If I query class A and include class B is there anyway I can have the query filter and/or sort by a field in class B? Your answer is actually pretty close to what I'm currently doing in doing the query then getting the field and manually processing the filter, but that just seems inefficient, especially as I need to throw out the majority of returned results.
0

According to the Parse Community:

Instead of dot notation in whereKey:, you would use whereKey:matchesKey:inQuery: or whereKey:matchesQuery:.

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.