Heads up! To view this whole video, sign in with your Courses Plus account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
In this video we'll remove rows of data from a table.
Important Notice About the findById()
Method
Since the recording of this workshop, the Sequelize findById()
method has been deprecated and replaced by the findByPk()
method.
Using the findByPk()
method, the code for the routes to get the delete article form and delete an article look like this:
/* Delete article form. */
router.get('/:id/delete', function (req, res, next) {
Article.findByPk(req.params.id).then((article) => {
res.render('articles/delete', { article: article, title: 'Delete Article' });
});
});
/* DELETE individual article. */
router.delete('/:id', function (req, res, next) {
Article.findByPk(req.params.id).then((article) => {
return article.destroy();
}).then(() => {
res.redirect('/articles');
});
});
Sequelize Methods
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up