Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
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. –  Timothy Walters Nov 4 '13 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 –  Akshat Agarwal Nov 4 '13 at 14:33

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
Thanks, I used query.include("locationID"); where locationID was a pointer column in my relationships table –  Akshat Agarwal Nov 8 '13 at 14:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.