Reputation: 147
I have two classes on Parse.com named Companies and Offers and the Offers class has a pointer column to Companies, so for every company there can be multiple offers. How can I create a query in android(Java) that will display all offers for a company based on the relationship?
Edit: Other details I didn't add:- There's actually four classes and they are: Offers, Companies, Venues and Cities. I need to get and display "offers" from all "venues" of a "company" in a "city" or cities.
Upvotes: 2
Views: 47
Reputation: 2316
ParseQuery<ParseObject> query = ParseQuery.getQuery("Offers");
query.whereEqualTo("yourCompanyPointerColumnName", yourCompanyParseObject);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> offersList, ParseException e) {
if (e == null) {
// Offers retrieved successfully
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
yourCompanyPointerColumnName
is the name of the column in your Offers
class which is a pointer to Companies
class.
yourCompanyParseObject
is the Company
object for which you want to retrieve Offers
for.
UPDATE:
To get all Offers
for all the Companies
, just remove the whereEqualTo
and this time use the include()
:
ParseQuery<ParseObject> query = ParseQuery.getQuery("Offers");
query.include("yourCompanyPointerColumnName");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> offersList, ParseException e) {
if (e == null) {
// All Offers retrieved successfully
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
Upvotes: 1