We are using operation "before save" for a model. We have a requirement where we want to delete previous record for an id. With Model hooks such as beforeCreate and beforeUpdate it was easier to delete the records only when creating i.e. destroyAll in beforeCreate but not beforeUpdate. It has become difficult with operation hooks.Could you please suggest a better way to achieve that using Operation Hooks? I have an option to use Model Hooks though.
Model.observe('before save', function (ctx, next) {
if(ctx.instance) {
ctx.instance.createdAt = ctx.instance.updatedAt = new Date();
} else {
ctx.data.updatedAt = new Date();
}
next();
});