January 2020 Answer
The thing to understand is that there's an update method for the Model and a separate update method for an Instance (record). Model.update()
updates ALL matching records and returns an array see Sequelize documentation. Instance.update()
updates the record and returns an instance object.
So to update a single record per the question, the code would look something like this:
SequlizeModel.findOne({where: {id: 'some-id'}})
.then(record => {
if (!record) {
throw new Error('No record found')
}
console.log(`retrieved record ${JSON.stringify(record,null,2)}`)
let values = {
registered : true,
email: '[email protected]',
name: 'Joe Blogs'
}
record.update(values).then( updatedRecord => {
console.log(`updated record ${JSON.stringify(updatedRecord,null,2)}`)
// login into your DB and confirm update
})
})
.catch((error) => {
// do seomthing with the error
throw new Error(error)
})
So, use Model.findOne()
or Model.findByPkId()
to get a handle a single Instance (record) and then use the Instance.update()