I have added a beforeSave() Parse cloud function defined that is not working correctly.
Here is the background: I have a class called UserRewards that has a column called user of type ParseRelation. It consists of exactly 1 relation which has a single object of type ParseUser. I have a new column pUser that I would like to set in this function. It looks up the user relation, finds the ParseUser in it, and sets pUser to that user.
Here's the code I have
Parse.Cloud.beforeSave("UserRewards", function(request, response) {
var relation = request.object.relation("user");
relation.query().find({
success: function(list) {
console.log("looked up relation");
if (list.length > 0) {
var pUser = list[0];
request.object.set("pUser", pUser);
console.log("updated pUser");
}
},
error: function(error) {
console.error("unable to lookup relation");
}
});
response.success();
});
When I update a UserRewards row, this function is being called. But it does nothing - no console or error logs whatsoever.
Any ideas?