Noha
Noha

Reputation: 15

How to get information from Object in class in Parse.com using JavaScript

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

Upvotes: 1

Views: 337

Answers (1)

Marius Waldal
Marius Waldal

Reputation: 9942

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");

Upvotes: 2

Related Questions