Sequelize模型实例有更新方法吗?

问题描述 投票:0回答:1

此代码是否有效?

    models.X.findOne({
       where: {
         id:bla
       }
    })
    .then(x => {
      // TODO: check if this will work or not?
      x
        .update({
          someProp: someVal
        })
        .then(() => {});
    });

我检查了文档,它说 update 是一个公共静态方法,所以我认为这段代码有效。

node.js sequelize.js
1个回答
1
投票
models.X.findOne({
    where: {
        id:bla
    } ,
    // raw : true // <--- Don't use this one , or else you will not get instance of model
}); // <--- This will return the instance of the X

是的,你可以做

x.update({ someProp: someVal });
© www.soinside.com 2019 - 2024. All rights reserved.