I have object Invitation
and linked object Event
I want to get last 10 objects of Invitation
where Event.date
is ordered by Descending
I'm doing this , but it doesn't work:
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();
Try this one: Try first query for the top 10 events. Then exec a new query on invitations where event is one of the ids you find in the first query
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
}
}
});
}
});
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.