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.
This commit is contained in:
Miroslav Bajtoš 2016-01-26 15:13:09 +01:00
parent 5b721fe016
commit 0fd7bf06b5
1 changed files with 6 additions and 1 deletions

View File

@ -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) {