1

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 !!

1
  • Do you have any idea how to solve my problem ? @BarbaraLaird Commented Apr 30, 2014 at 17:10

1 Answer 1

2

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");
Sign up to request clarification or add additional context in comments.

8 Comments

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
Thank u very much it works well ,, just I change some places and it worked Thaaaaanks @Handsomeguy
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
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?
oh ya this is the problem , there is no real location in database lol @Handsomeguy Thank u man u really made my day and I feel I am idiot lol
|

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.