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 update rows of data in 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 edit article form and update an article look like this:
/* Edit article form. */
router.get('/:id/edit', function (req, res, next) {
Article.findByPk(req.params.id).then((article) => {
res.render('articles/edit', { article: article, title: 'Edit Article' });
});
});
/* PUT update article. */
router.put('/:id', function (req, res, next) {
Article.findByPk(req.params.id).then((article) => {
return article.update(req.body);
}).then((article) => {
res.redirect('/articles/' + article.id);
});
});
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