WDI-SEA / project-2-issues

0 stars 0 forks source link

Sequelize updating questions #21

Closed cory-yonomi closed 2 years ago

cory-yonomi commented 2 years ago

I am struggling to get updates to data to actually take. Have tried multiple combinations of .set() and .save() and .update(). Have tried puts and posts. The console log in the code below won't go off but it redirects otherwise.


router.post('/:id', isLoggedIn, (req, res) => {
    db.stream.findByPk(req.params.id)
        .then(foundStream => {
            foundStream.update({
                name: req.params.name,
                longitude: req.params.longitude,
                latitude: req.params.latitude
            })
            console.log(foundStream)
            foundStream.save()
            res.redirect(`streams/${req.params.id}`)
    }).catch(err => console.log(err))
})```
DoireannJane commented 2 years ago

Can you show me how stream and foundStream are set up?

TaylorDarneille commented 2 years ago

Here are the notes on this too https://gasei.gitbook.io/sei/05-node-express/express-mongoose#update

cory-yonomi commented 2 years ago

I was missing method_override and using req.params instead of req.body when trying to update.