Skip to content

Instantly share code, notes, and snippets.

@xolubi
Last active August 29, 2015 14:11
Show Gist options
  • Save xolubi/c6683dca5a88724eed01 to your computer and use it in GitHub Desktop.
Save xolubi/c6683dca5a88724eed01 to your computer and use it in GitHub Desktop.
Strip uniques before update (SAILS)
stripUniques: function(id, data, cb){
this.findOne({id: id}).exec(function findCB(err, result){
if (err) {
//bubble error back to callback
return cb(err);
} else if (!result) {
//id passed is invalid. return empty object and deal with this in callback
return cb(null, {});
} else {
if (data) {
//do this for all uniques in model
if (data.name && result.name == data.name) {
delete data.name;
}
return cb(null, data);
} else {
//data is empty. return empty object
return cb(null, {});
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment