简体   繁体   中英

Parse.com Query on Pointer value

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?

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") .

According to the Parse Community:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM