loopback-connector-redis
loopback-connector-redis copied to clipboard
Upserting an existing records returns all fields as strings
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
}
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));
}
Made a PR anyway..