I use Parse.com for the backend of my app. I use Cloud Code. I have 2 classes :
AllStudents : nameID, firstName, address, city, bike, description
Details : NameID, Bike, Description
AllStudents class : columns nameID
, firstName
, address
, city
are populated. Columns bike
and description
class are empty.
Details class : columns NameID
, Bike
, Description
are populated.
I want to populate the columns bike
and description
of AllStudents
class with columns Bike
and Description
(Details
class), thus to update each rows of my AllStudents
class. As nameID
and NameID
have the same value, I use it to "join" the classes.
I know that I could use Relational Datas but for the purpose of my app I need to populate the AllStudents
class.
Here is my code. The problem is that the columns bike
and description
are well populated but with the same value : for bike:"Mountain Bicycles" and for description:"Blue and red". It's the value of my last row in Details
class. I don't understand why, do you have any idea ?
Parse.Cloud.define("MyFunction", function(request, response) {
var Students = Parse.Object.extend("AllStudents");
var studentsQuery = new Parse.Query(Students);
var Details = Parse.Object.extend("Details");
var detailsQuery = new Parse.Query(Details);
studentsQuery.matchesKeyInQuery("nameID", "NameID", detailsQuery);
studentsQuery.find({
success: function(resultats) {
for (var i = 0; i < resultats.length; i++) {
var object = resultats[i];
studentsQuery.get(object.id, {
success: function(resultat) {
detailsQuery.equalTo("NameID", object.get('nameID'));
detailsQuery.find({
success: function(results) {
var objectif = results[0];
resultat.set({ bike: objectif.get('Bike'), description: objectif.get('Description')});
resultat.save();
}
});
},
error: function(object, error) {
}
});
}
}
});
});
Thanks for your help !