首页 > 解决方案 > 环回的 upsertWithWhere() 中的问题

问题描述

我正在使用loopback3.x。为什么 upsertWithWhere 函数总是更新同一个实例?当 updateWithWhere 函数执行时,始终只有一个实例。

app.models.oneTimePassword.upsertWithWhere({
    where: {
        userId: user.id
    }
}, {
    userId: user.id,
    otp: otp,
    updatedAt: updatedAt,
    type: 'email'
}, (err, res) => {
    if (!err) {
        callback(null, {
            status: "OK",
            message: "email sent"
        });
    } else {
        callback(err);
    }
});

标签: loopbackjs

解决方案


app.models.oneTimePassword.upsertWithWhere(
  {
    userId: user.id
  },
  {
    userId: user.id,
    otp: otp,
    updatedAt: updatedAt,
    type: 'email'
  },
  (err, res) => {
    if (!err) {
        callback(null, {
            status: "OK",
            message: "email sent"
        });
    } else {
        callback(err);
   });

试试这个,第一个参数upsertWithWhere应该是where因此,你不需要添加where: {}查看这个官方文档


推荐阅读