I have a parent object "Listing" (think real estate listing), that can have multiple child objects "Image".
I'm trying to implement a Cloud Code function that marks all the child objects as archived when I archive their parent.
For some reason the query result is always empty. I can't see why. My "Error: image undefined" error appears each time.
The Image class has a pointer to Listing, but there's no relation from Listing to Image.
Parse.Cloud.afterSave("Listing", function(request) {
Parse.Cloud.useMasterKey();
// Handle archiving. If a listing is marked as archived, mark the image as archived also.
query = new Parse.Query("Image");
query.equalTo("listing", request.object);
query.first({
success: function(image) {
if (typeof image != "undefined") {
image.archived(request.object.get("archived"));
image.save();
console.log("Done");
}
else {
console.log("Error: image undefined.");
}
},
error: function(error) {
console.error("Got an error " + error.code + " : " + error.message);
},
});
);
Any help appreciated.