From 0fd7bf06b52be1ffefd47f3912845a0ea04bf5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 26 Jan 2016 15:13:09 +0100 Subject: [PATCH] Register Models with Dynamic converter Fix `RemoteConnector.prototype.resolve` to register new models with strong-remoting's `Dynamic` type resolver. Before this change, if loopback-connector-remoting ended up with its own copy of strong-remoting, then the responses were not converted from plain objects to model instances, because model converters were registered with the other instances of strong-remoting. This has a side-effect that when there is only one strong-remoting instance in the app, then there will be multiple converters registered for the same model. Since the code performing conversion takes into account the first model only, this should not pose any issues. --- lib/remote-connector.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/remote-connector.js b/lib/remote-connector.js index 624ee31..848c9d5 100644 --- a/lib/remote-connector.js +++ b/lib/remote-connector.js @@ -40,7 +40,7 @@ function RemoteConnector(settings) { // handle mixins in the define() method var DAO = this.DataAccessObject = function() { }; - + } RemoteConnector.prototype.connect = function() { @@ -77,6 +77,11 @@ RemoteConnector.prototype.resolve = function(Model) { createProxyMethod(Model, remotes, remoteMethod); } }); + + // setup a remoting type converter for this model + remotes.defineType(Model.modelName, function(val) { + return val ? new Model(val) : val; + }); }; function createProxyMethod(Model, remotes, remoteMethod) {