Skip to content

Instantly share code, notes, and snippets.

@MitsuhaKitsune
Created January 19, 2018 14:16
Show Gist options
  • Save MitsuhaKitsune/4d73baad6d4e134e66b6cba9d47d0a2e to your computer and use it in GitHub Desktop.
Save MitsuhaKitsune/4d73baad6d4e134e66b6cba9d47d0a2e to your computer and use it in GitHub Desktop.
Update or create helper for waterline on SailsJS
// Include this code on your config/models.js
updateOrCreate: function(criteria, values){
var self = this;
if (!values) values = criteria.where ? criteria.where : criteria;
return this.findOne(criteria).then(function (result){
if (result) {
return self.update(criteria, values);
} else {
return self.create(values);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment