Reputation: 2258
Can you edit data in beforeSave callback and if yes, how?
Looking at various docs, it seem like this code should work (using "_User"
or Parse.User
) and I can see Ran beforeSave on a User
and new user!
in my logs but the key aaa
is still empty..
I've tried to add user.save()
after user.set
but still no luck.
Any idea?
Parse.Cloud.beforeSave("_User", function(request, response) {
console.log('Ran beforeSave on a User');
var user = request.object;
if(user.existed()) {
response.success();
} else {
console.log('new user!');
user.set('aaa', 'xxx');
response.success();
}
});
EDIT 2015/12/03: Maybe critical info, this code is running on heroku. http://blog.parse.com/announcements/introducing-heroku-parse/
EDIT 2015/12/05: It seem to be a bug with Heroku / Parse integration. beforeSave hook are called but doesn't seem to allow you to edit the request.object..
EDIT 2015/12/07: I've created an issue on the CloudCode-Express
repo https://github.com/ParsePlatform/CloudCode-Express/issues/6
Upvotes: 1
Views: 199
Reputation: 38506
Using Webhooks, you need to pass back the changed object:
response.success(object);
Upvotes: 1
Reputation: 2717
Change your code to use isNew()
method:
Parse.Cloud.beforeSave(Parse.User, function(request, response) {
console.log('Ran beforeSave on a User');
if(!request.object.isNew()) {
response.success();
} else {
console.log('new user!');
request.object.set('aaa', 'xxx');
response.success();
}
});
Upvotes: 0