【问题标题】:Is instance of squalize model have update method?squalize 模型的实例是否有更新方法?
【发布时间】:2019-03-22 13:54:48
【问题描述】:

此代码是否有效?

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

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

【问题讨论】:

    标签: node.js sequelize.js


    【解决方案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 });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-12
      • 2015-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多