如何通过Parse.com中链接对象的colum排序查询?

时间:2015-11-26 12:30:28

标签: java parse-platform

我有对象Invitation和关联对象Event enter image description here enter image description here

我希望得到Invitation的最后10个对象,其中Event.date降序排序

我这样做,但它不起作用:

                ParseObject parseUser = user;

                ParseQuery eventQuery = ParseQuery.getQuery("Event");
                eventQuery.whereLessThan("date", new Date());
                eventQuery.orderByDescending("date");
                eventQuery.setLimit(10);

                ParseQuery<ParseObject> invitationQuery = ParseQuery.getQuery("Invitation");
                invitationQuery.whereEqualTo("user", parseUser);
                invitationQuery.whereMatchesQuery("event", eventQuery);

                List<ParseObject> list= invitationQuery.find();

1 个答案:

答案 0 :(得分:1)

试试这个: 尝试查看前10个事件的第一个查询。然后对邀请执行一个新查询,其中事件是您在第一个查询中找到的ID之一

ParseQuery eventQuery = ParseQuery.getQuery("Event");
eventQuery.whereLessThan("date", new Date());
eventQuery.orderByDescending("date");
eventQuery.setLimit(10);
eventQuery.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> objects, ParseException e) {
                ArrayList<ParseObject> eventsIds = new ArrayList<ParseObject>();
                if (e == null) {                    
                     for (ParseObject event : objects) {
                        eventsIds.add(ParseObject.creatWithoutData("event",event.getObjectId()));
                     }

                     ParseQuery<ParseObject> invitationQuery = ParseQuery.getQuery("Invitation");
                     invitationQuery.whereEqualTo("user", parseUser);
                     invitationQuery.whereContainedIn("event", eventIds);
                     invitationQuery.findInBackground(new FindCallback<ParseObject>() {
                                     @Override
                                     public void done(List<ParseObject> objects, ParseException e) {
                                       //Do whatever you want with your events
                                     }
                            }
                     });
            }
        });