loopback-connector-redis icon indicating copy to clipboard operation
loopback-connector-redis copied to clipboard

Upserting an existing records returns all fields as strings

Open penguinpowernz opened this issue 9 years ago • 2 comments

It will only display itself when you use the upsert route while specifying an ID:

This will not do it:

PUT /hvacs { installed: true, enabled: false}
---
{
  "installed": true,
  "enabled": false
}

But when you pass the ID to modify an existing:

PUT /hvacs { id: 1, installed: true, enabled: false}
---
{
  "installed": "true",
  "enabled": "false"
}

Even if the model doesn't already exist:

PUT /hvacs { id: 999, installed: true}
{
  "installed": "true",
  "id": 999
}

penguinpowernz avatar Nov 13 '16 23:11 penguinpowernz

I narrowed it down to the ok() method in the BridgeToRedis.prototype.updateOrCreate method. Someone forgot to call fromDb on the resulting object to convert the fields to their various types.

This fixes it:

Need this at the head of the function:

  var self = this;

The change the ok function to this:

    function ok() {
      callback(error, self.fromDb(obj));
    }

penguinpowernz avatar Nov 13 '16 23:11 penguinpowernz

Made a PR anyway..

penguinpowernz avatar Nov 14 '16 00:11 penguinpowernz