Model.updateAttribute不更新任何内容

时间:2019-07-05 19:42:29

标签: node.js loopbackjs

我正在尝试更新属性,但它完全没有改变

我尝试了upsertWithWhere,但没有运气

我有这个模型

{
  "name": "worker",
  "plural": "workers",
  "base": "PersistedModel",
  "idInjection": false,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "id": {
      "type": "number",
      "id": true
    },
    "name": {
      "type": "string"
    },
    "company-name": {
      "type": "string"
    },
    "email": {
      "type": "string"
    },
    "orderId": {
      "type": "number"
    }
  }

当我创建一个新实例时,我有这个

{ name: 'trabajador',
  'company-name': 'ibm',
  email: 'e@mail.com',
  id: 1 }

但是当我尝试使用此功能更新它

await Worker.findOne({where: {id:workerId}}).then(res => {
                if (!res) { throw "There are no workers with Id " + workerId }
                console.log(res)
                res.updateAttribute({orderId: orderId}).then(res => {console.log(res)}).catch(err => {throw err})
            }).catch(err => {throw err})

它什么也没做。它返回不带想要的orderId属性的相同实例。

我希望输出类似于

{ name: 'trabajador',
  'company-name': 'ibm',
  email: 'e@mail.com',
  id: 1,
  orderId: 1
 }

但是我却没有 orderId

1 个答案:

答案 0 :(得分:0)

使用:

res.updateAttribute('orderId', orderId); // one attribute

res.updateAttributes({orderId: orderId}); // multiple attributes