Chintan Soni
Chintan Soni

Reputation: 25267

android + parse : join two tables and query it

This is regarding Parse backend.

I have two tables:

Event: objectId, contact, heading, latlng, noi, ACL, parent, user(pointer to User), data_to, featured, weblink, updatedAt, organization(pointer to Organization), address, emailid, tags, major, rsvp(boolean), createdAt, image, date_from, description, is_major_event, group(pointer to Group)

Event_stat: objectId, ACL, createdAt, event(pointer to Event), rsvp(join/maybe/seen), updatedAt, user(pointer to User)

I want to join these tables and resultant table will be used to query like:

Select * from [join result] where event_stat_user="asdcvb" AND organization="abc" AND (event_stat_rsvp="join" OR rsvp="maybe") sortby event_stat_updatedAt

Can anyone help me how can i achieve this in Android ?

Upvotes: 0

Views: 723

Answers (1)

Chintan Soni
Chintan Soni

Reputation: 25267

I found a way to create a sub query:

ParseQuery<ParseObject> query = new ParseQuery("event_stats");
query.setLimit(1000);
query.whereEqualTo("user", ParseUser.getCurrentUser());
ParseQuery<ParseObject> parseInnerQuery = new ParseQuery<>("event");
parseInnerQuery.whereEqualTo("organization", ParseObject.createWithoutData("organization", Data.getValue(OrganizeActivity.CURRENT_ORGANIZATION)));
query.whereMatchesQuery("event", parseInnerQuery);
query.include("event");
query.findInBackground(new FindCallback<ParseObject>() {
    @Override
    public void done(List<ParseObject> list, ParseException e) {

        if (e == null && list != null && list.size() != 0) {
            List<Event> listEvent = new ArrayList<Event>();
            for (ParseObject parseObject : list) {
                listEvent.add(Event.getEventById(getValue(parseObject, "event")));
            }
            masterEventAdapter.setEvents(listEvent);
            } else {
        }
    }
});

Upvotes: 1

Related Questions