“Category.Company” is not a child column. It is not even a column. It is simply a “reminder” to you that the “Category” table has the “Company” column which references the “Company” table.
Based on what criteria do you want to load the company object with the category name?
There are several ways to load the related data. Basically, you will need either relation auto-loading or single-step retrieval.
Please check out the documentation about Related Data retrieval
Yeah, but is the other way round. I want to load category table (parent table) from the company Table (child table). This is code am using for now, but takes a long time to load the company object, since for every loop in the company objects it will check company.object id in the category table to get the corresponding category name.
function jsonData(){
var companiesList = companiesStorage.find(dataQuery);
// this.companies = ko.mapping.fromJS(companiesList.data);
var jasonStr = JSON.stringify(companiesList.data)
var jsonObj = JSON.parse(jasonStr);
for (var i = 0, len = jsonObj.length; i < len; i++) {
var cid = jsonObj.objectId;
var cat = getCat(cid);
var singleItem = jsonObj;
singleItem.Category = cat[0].CategoryName;
// console.log(cat[0]);
} ;
return jsonObj;
}
function getCat(id) {
var categoryStorage = Backendless.Persistence.of( Category);
var dataQuery = new Backendless.DataQuery();
dataQuery = {properties:["CategoryName"],
condition: "Company.objectId='" + id + "'"};
var catlist = categoryStorage.find(dataQuery);
return catlist.data;
};
If you enable an auto-loading for Company’s Category column, you will be able to get your categories along with your companies in single request to the server :
var companies = companiesStorage.find(dataQuery).data;
for (var i = 0, i < companies.length - 1; i++) {
var company = companies[і]
console.log(company.CompanyName, company.Category.CategoryName)
}
The problem is that your Company table does not contain relation to Category table, but the Category contains Company. so to resolve your task you have to add relation Category to Company table, than you will able to load categories.
I have three tables Company and Reviews and users.
I want to get a list of company and the total no of reviews plus the most recent review and the user who gave that review.