Android : Get objects from multiple Relations

Say, I have a Food class, in which I have 3 relations - 'Lovers', 'Eaters', 'Makers'. I added users to each of these relations.

Now I want to display for a particular food, a list which shows all 'Lovers' first, then 'Makers', and all 'Eaters' at the end - in this order.

So to retrieve only Lovers, I have to do ParseQuery on Lovers, and then find(), from which I store the list of users in an ArrayList. Then again I repeat the same procedure for Makers and Eaters and append the result to my ArrayList.

This process is slow, tedious and resource consuming. Is there a better way ?

EDIT
Food class(ParseObject) is as follows
  • Lovers - Relation<_User>
  • Eaters - Relation<_User>
  • Makers - Relation<_User>
  • --- and other variables like cuisine, country, etc ---
User class(ParseUser) is as follows ##
  • name
  • age

Every food makes a 'Lovers' relation with users who love the food, same for 'Eaters' and 'Makers'

To get Lovers, then Makers and then Eaters for a 'food' object, I use following query

ArrayList<User> userList = new ArrayList<User>();

ParseRelation<ParseObject> relation = food.getRelation("Lovers");
ArrayList<User> lovers =relation.getQuery().find();

ParseRelation<ParseObject> relation = food.getRelation("Makers");
ArrayList<User> makers =relation.getQuery().find();

ParseRelation<ParseObject> relation = food.getRelation("Eaters");
ArrayList<User> eaters =relation.getQuery().find();

userList.add(lovers);
userList.add(makers);
userList.add(eaters);

Unfortunately Parse does not support 'include' in query on relations and I dont want to use Array to store the relationship (coz in future I may need to find what a user loves, eats and makes). So, is there a solution get these 3 relations data in single query.

Answers


One option would be to create a class to be your join table, as is done in some of the samples provided on Parse.

UserFood:
User: link to User class
Food: link to Food class
MakesIt: bool
LovesIt: bool
EatsIt: bool

Getting all users for a food becomes a simple query, getting all foods for a user becomes simple. If you just want a list of 'Lovers' you can filter on the 'LovesIt' = true.

It also makes it easy to do a query like: find my all foods where the person that makes it also eats it.


Need Your Help

Using UIActivityIndicator in MKMapView

iphone ios mkmapview uiactivityindicatorview

In my app I download kml files and show their data in the map.How to show an activity indicator while downloading the data(after tapping the UIButton that initializes the downloading process and st...

How can I handle onTap events on path based map overlays?

android path overlay android-mapview

I'm currently making an android map based app. The purpose of this app is to display complex overlays on a mapview. To do this I'm using custom overlays and overriding draw() function.