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 in parse.com the class MainBranch and it contains objects in columns Customer and Location which are pointing to another classes ((User and locations )) and I need some information from those two classes but I can not reach to them.

My output after running give me [Object Object]

My JavaScript code :

    var order = Parse.Object.extend("MainBranch");
    var query = new Parse.Query(order); 

    query.find({
        success: function(results) {

        alert("Successfully retrieved " + results.length + " Orders.");

        var orid1 = results[2].get("OrderId")
        document.getElementById("intro").innerHTML = orid1;

        orid1 =  results[2].get("Customer");
        document.getElementById("intro1").innerHTML = orid1;

        orid1 =  results[2].get("TotalPrice");
        document.getElementById("intro2").innerHTML = orid1;

        orid1 =  results[2].get("Location");
        document.getElementById("intro3").innerHTML = orid1;

        orid1 =  results[2].get("Date");
        var orid2 =  results[2].get("Time");
        document.getElementById("intro4").innerHTML = orid1+"<br>"+orid2;

        },
        error: function(error) {
        alert("Error: " + error.code + " " + error.message);
        }
        });

from my searching I found that relations are necessary thus I tried many ways but i did not undrestand relations clearly and I did not find the solution yet. any help please !!

share|improve this question
    
Do you have any idea how to solve my problem ? @BarbaraLaird –  Noha Apr 30 at 17:10

1 Answer 1

up vote 1 down vote accepted

You can include those objects using

query.include("Customer");
query.include("Location");

This will fetch the related objects together with the MainBranch objects:

var customer = results[2].get("Customer");
share|improve this answer
    
I do like you said and then I added -- customer.get("username"); -- because I need the user name, Is it correct ? because it gave me output: undefined @Handsomeguy –  Noha Apr 30 at 17:47
    
Thank u very much it works well ,, just I change some places and it worked Thaaaaanks @Handsomeguy –  Noha Apr 30 at 18:00
    
Great, glad it worked out –  Handsomeguy Apr 30 at 18:09
    
customer object worked correctly but location object is not !! despite I code them exactly the same .. Is it affect if i use two includes ?!!! do u have any idea? @Handsomeguy –  Noha Apr 30 at 19:49
    
You can use include on several pointers. What kind of object is Location? Are you sure the object you're checking really has a location? –  Handsomeguy Apr 30 at 19:58

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.