简体   繁体   English

Parse.com指针值查询

[英]Parse.com Query on Pointer value

I'm using Parse.com for my android apps database. 我正在将Parse.com用于我的android apps数据库。

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? 简而言之,我正在查询具有指向类B的字段的类A。如果我查询类A并包含类B,则无论如何我都可以对类B中的字段进行查询过滤和/或排序?

I'm more familiar with sql style db as may become obvious from my description. 我对sql风格的db更加熟悉,从我的描述中可能会变得很明显。 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. 在解析中,我有一张表格供邀请游戏“ gameInvitees”的人使用,其中包含一些元数据,例如何时邀请他们以及他们的rsvp状态。 Then a separate table with the games "gameInstances". 然后是带有游戏“ gameInstances”的单独表。 The "gameInvitees" include a pointer to the game they are invited to and the parse user that is invited. “ gameInvitees”包括指向他们被邀请参加的游戏的指针和被邀请的解析用户。

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. 我的问题是我正在尝试查询“ gameInvitees”表,以便可以基于“ gameInstance”表中的游戏时间找到被邀请加入游戏的当前用户。

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"); 从表的类型创建一个ParseObject: ParseObject time = new ParseObject("Date"); Then get the ParseObject from the result: time = result.getParseObject(pointer_field); 然后从结果中获取time = result.getParseObject(pointer_field);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") . 现在,您可以像平时一样从time中提取其具有的任何字段,例如: time.getString("some_field")

You may also need to include: query.include("pointer_field") . 您可能还需要包括: query.include("pointer_field")

According to the Parse Community: 根据解析社区:

Instead of dot notation in whereKey:, you would use whereKey:matchesKey:inQuery: or whereKey:matchesQuery:. 可以使用whereKey:matchesKey:inQuery:或whereKey:matchesQuery:代替whereKey:中的点符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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