You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating instance/class methods, remember to return!
Instead of reaching for a findAll and then trying to chain, think about using update or destroy
Common methods: findById, findAll, findOrCreate, create, destroy, update
Update method takes ({values}, {options.where, options.returning}). When returning: true, promise will return the actual value updated, accessible via .then(data => data[1][0])
Hooks will take a function with the first parameter being the instance, and the second being options
Sample Code
Querying
Model.findAll({
attributes: ['name'],
where: {x === true},
order: '"asdf" DESC'
})
.then()
.catch(err => console.error("we have an error!", err))
Hooks
hooks: {
beforeUpdate: function(article) { // gets the article instance we're trying to update
article.version++;
}
}
app.get('/forbidden', function(req, res, next) {
res.sendStatus(403); // contrived, but we'll be able to send status 403 if user tries to access this
});
Error Handling: Main
app.use(function (err, req, res, next) {
if (err) res.sendStatus(500); // general error handler. do whatever we want here
});