Let's say we create a sails.js model, which sometimes should be saved into DB when posted (as usual), and sometimes – should not. Can we perform this logic in a model lifecycle callback?
Basically, it gives us just two ways – proceed as usual calling next() or raise an error calling next(err). Are there any other options? Maybe it's somehow possible to get access to req/res objects from inside the callback?
module.exports = {
attributes: {
},
// Lifecycle Callbacks
beforeCreate: function(values, next) {
//analyze values
if (someCondition) {
//now we realize that we don't want the model to be created
//we need perform some other stuff and respond with some custom answer
//how do we do that?
} else {
next();
}
}
};