Make sure these boxes are checked before submitting your issue -- thanks for reporting issues back to Parse Server!
In main.js add
var Testing1 = Parse.Object.extend('Testing1');
Parse.Cloud.beforeSave('Testing1', function(req, res) {
var obj = req.object;
console.log('In b4 save Testing1', obj.toJSON());
obj.set('override', Date.now());
res.success(obj);
});
Parse.Cloud.define('test', function(req, res) {
var t1 = new Testing1({ name: 'X' });
t1.save()
.then(o => {
console.log('After saving', o.toJSON());
res.success(o);
})
.fail(err => res.error(err.message));
})
The result:
{
"result": {
"name": "X",
"createdAt": "2016-03-06T10:22:20.041Z",
"updatedAt": "2016-03-06T10:22:20.041Z",
"objectId": "eyw0agyTof",
"__type": "Object",
"className": "Testing1"
}
}
override attribute not set as expected
I was just working on this and submitted #865 to correct this for an older issue. :+1: It will be fixed in the next release.
@gfosco awesome, but wonder if theres a workaround for the time being? I use beforeSave to modify stuff in alot of places ...
@gfosco Any timeline on the next release with this fix?
+1, any info?
Still having this issue on "parse-server": "^2.1.5", (just re-run the code example of @jiewmeng with the same result)
Shouldn't the 2.1.5 release have fixed it? Am I missing something?
Thanks.
I still seem to have this problem on version 2.2.4. Am I doing something wrong here? My code looks identical to the example @jiewmeng provided.
I am using version 2.2.7 and seems that after you changed the request.object your have to call response.success() rather than response.success(request.object)
@ flovilmart , @gfosco , it seems that @flavionegrao solution works. It seems that if in the beforeSave I add a new field to the object being save and call response.success("some string) then the new field is not being added to the object being saved, but if I do response.success() it does add the filed?
Most helpful comment
I am using version 2.2.7 and seems that after you changed the request.object your have to call
response.success()rather thanresponse.success(request.object)