4
我正在修改我的模型的after save
操作挂钩上的ctx.result
以简化POST方法的响应。响应应该只包含生成id
和响应只不是模型的一部分属性:修改ctx.result不会更改POST响应
MyModel.observe('after save', function(ctx, next) {
if (ctx.instance && ctx.isNewInstance) {
ctx.result = {
id : ctx.instance.id,
responseOnlyProperty: MyModel.getResponseOnlyPropertyValue()
};
console.log('result:', ctx.result);
}
next();
});
正如预期的那样ctx.result
写入设置新值控制台,但响应正文发送回客户端仍包含所有模型属性,并且不包含新添加的responseOnlyProperty
。
修改响应体的正确方法是什么?