Parse cloud returning empty ParseObject ( empty estimatedData) if changing value

for(var i=0; i < results.length; i++){
var currSkill = results[i];
currSkill.set(“name”,‘test’);
}
}
return results;

If I change this parseObject in the cloud code the results array return ParseObject of type Skill but empty but if I don’t change hence if I don’t write

currSkill.set(“name”,‘test’);

it return with values… Anyidea why and how I can fix it ?

Can you please share the whole code of the cloud code function?

we ended up doing something else but anyway here’s what it looked like

Parse.Cloud.define(‘updateObjectWithoutSave’, async function(req,res){
var skillQuery = new Parse.Query(‘Skill’);
try{
var results = await skillQuery.find();
for(var i=0; i < results.length; i++){
var currSkill = results[i];
currSkill.set(“name”,‘test’);
}
}
return results;
}catch(e){
throw new Error(e)
}

});

I was able to reproduce the problem and I also checked the open source code. Since the object is dirty, its attributes are not sent. You’d need to save it before returning. Or you can use this code:

Parse.Cloud.define('updateObjectWithoutSave', async function() {
  const skillQuery = new Parse.Query('Skill');

  const results = await skillQuery.find();

  return results.map(currSkill => {
    currSkill.set('name', 'test');
    return currSkill._toFullJSON();
  });
});
1 Like

Thank you Davi! This community is just awesome :heart_eyes:

1 Like

Parse.Cloud.define(‘fetchServices’, async function(req,res){

var categoryQuery = new Parse.Query('Category');
try{
    const categoriesList = await categoryQuery.find();
    var serviceQuery = new Parse.Query('Service');
    serviceQuery.limit(1000);
    var servicesList = await serviceQuery.find();
    
    console.log("Category is " + categoriesList[0].get("name"));

        return servicesList.map(service => {

            service.set('category',categoriesList[0]);
            return service._toFullJSON();
          });
   
   // return servicesList;
}catch(e){
    throw new Error(e);
}

});

For some reasons with this function the Category Object is still empty…

try:

const serviceJSON = service._toFullJSON();
serviceJSON.category = categoriesList[0];
return serviceJSON;
1 Like

It worked! Thank you for I learned how to deal with dirty objects, very useful indeed!

1 Like