I know that Sails automatically creates an entry when you pass the appropriate fields to it through the creation URL. When a new record is created, I need to see if the record exists or not. If it does not exist, I create it. If it exists, I should not create it. I have successfully checked if the record exists or not, but I am confused about what to do if the record exists. How can I say that Sails did not create a record?
beforeCreate: function(values, cb) {
User.findOne({ where: { name: values.name}}).exec(function(err, found) {
if(found == undefined) console.log("NOT FOUND");
else console.log("FOUND");
});
cb();
}
When Sails gets in cb()
, it automatically creates a record. How can I do this to decide whether to create a record?
source
share