Loopback:没有使用upsert接收插入对象的id

时间:2015-08-04 10:16:08

标签: mysql node.js strongloop upsert loopback

我在环回代码中有这个upsert;

它在更新时非常有效,但是当插入新地址时,它会返回0我正在传递它,而不是在数据库中创建的新地址ID。

这是我的Upsert的代码:

promise.then(function(data) {
      var address = new app.models.Address();
      if(data[0].addressId) {
        address.addressId = data[0].addressId; //id
      } else {
        address.addressId = 0;
      }
      address.street = dataUpdate.address.street;
      address.zipCode = dataUpdate.address.zipCode;
      address.city = dataUpdate.address.city;
      address.province = dataUpdate.address.province;
      address.country = dataUpdate.address.country;
      address.latitude = dataUpdate.address.latitude;
      address.longitude = dataUpdate.address.longitude;

      app.models.Address.upsert(address, function (err, objAddress) {
        if (err) throw err;
        cb(null, objAddress);
      });
}, function(err) {
  console.log(err);
});

非常感谢!

0 个答案:

没有答案