0

I have 3 classes "campaigns", "relationships" and "locations" on parse.com I have a query to hit the campaigns table and get its information by

var query = new Parse.Query("Campaigns");
query.find({
    success: function(results) {            
    },
    error: function(){
        response.error("failed to get a respose");
    }   
});

Now I want to hit the locations table by navigating through the relationships table. (the relationships table has a column which stores the object IDs of the campaigns in the campaigns class). How do I access the corresponding data from the "locations" table? I know I have to make another query but I cant find the correct syntax.

for android (java) the syntax would be something like-

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Campaigns");
ParseQuery<ParseObject> query2 = new ParseQuery<ParseObject>("Relationships");

ob2 = query.find();
for (ParseObject object : ob2) {
    ParseObject Locations = new ParseObject("Campaigns");

    query2.whereEqualTo("campaignIDString", object.getObjectId());
    query2.include("locationID");   //the pointer column it must have
    try {
        ob = query2.find(); //this holds the locations Table data
    }
}

Sorry about the formatting, not very used to SO formatting yet

2
  • 1
    How many locations do you expect to have per campaign? Do you need any extra information about a campaign/location join or is it a simple relationship? Depending on the answer to those questions there might be a much simpler way to do what you want to do. Commented Nov 4, 2013 at 4:31
  • @TimothyWalters There is 1 location per campaign, on the campaigns class there are columns like campaignID, province, city. I need all 3 of them per campaign Commented Nov 4, 2013 at 14:33

1 Answer 1

1

Based on your comment, it sounds like you would be better off simplifying your classes to just "Campaigns" and "Locations", and adding a "location" property to the "Campaigns" class.

Once you do that, just query.include("location"); anytime you query a Campaign and want to include the location it relies on.

If this isn't an option, please expand your question with the schema of each class and the shape of the data you want to get back in your query.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I used query.include("locationID"); where locationID was a pointer column in my relationships table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.