loopback-datasource-juggler icon indicating copy to clipboard operation
loopback-datasource-juggler copied to clipboard

`Model._forDB` is not invoked in `update` function

Open matmoi opened this issue 3 years ago • 0 comments

Steps to reproduce

There's an inconsistency when calling update and save with the same data parameter.

Current Behavior

In update, invokeConnectorMethod is passing data as is, without invoking Modal._forDB as in here. As a result, an Array type is not stringified in the update function, which leads to an error in the postgres connector.

Expected Behavior

update should use Model._forDB on the input data, similarly to save, create, replaceById and updateAttributes.

Link to reproduction sandbox

No link

Additional information

This patch fixes the issue :

diff --git a/lib/dao.js b/lib/dao.js
index ef59eaea..275a0008 100644
--- a/lib/dao.js
+++ b/lib/dao.js
@@ -2356,7 +2356,7 @@ DataAccessObject.updateAll = function(where, data, options, cb) {
     Model.notifyObserversOf('persist', context, function(err, ctx) {
       if (err) return cb(err);
       data = ctx.data;
-      invokeConnectorMethod(connector, 'update', Model, [where, data], options, updateCallback);
+      invokeConnectorMethod(connector, 'update', Model, [where, Model._forDB(data)], options, updateCallback);
     });
   }
   return cb.promise;

matmoi avatar Aug 06 '22 13:08 matmoi