diff --git a/lib/remote-connector.js b/lib/remote-connector.js index 08e5708..6c833f6 100644 --- a/lib/remote-connector.js +++ b/lib/remote-connector.js @@ -83,7 +83,7 @@ function createProxyMethod(Model, remotes, remoteMethod) { var scope = remoteMethod.isStatic ? Model : Model.prototype; var original = scope[remoteMethod.name]; - scope[remoteMethod.name] = function remoteMethodProxy() { + function remoteMethodProxy() { var args = Array.prototype.slice.call(arguments); var lastArgIsFunc = typeof args[args.length - 1] === 'function'; var callback; @@ -98,6 +98,11 @@ function createProxyMethod(Model, remotes, remoteMethod) { var ctorArgs = [this.id]; return remotes.invoke(remoteMethod.stringName, ctorArgs, args, callback); } + + scope[remoteMethod.name] = remoteMethodProxy; + remoteMethod.aliases.forEach(function(alias) { + scope[alias] = remoteMethodProxy; + }); } function noop() { diff --git a/test/remote-connector.test.js b/test/remote-connector.test.js index f2909f9..ad3038d 100644 --- a/test/remote-connector.test.js +++ b/test/remote-connector.test.js @@ -70,4 +70,19 @@ describe('RemoteConnector', function() { done(); }); }); + + it('should support aliases', function(done) { + var RemoteModel = loopback.PersistedModel.extend('TestModel'); + RemoteModel.attachTo(this.remote); + + var ServerModel = this.ServerModel; + + ServerModel.upsert = function(id, cb) { + done(); + }; + + RemoteModel.updateOrCreate({}, function(err, inst) { + if (err) return done(err); + }); + }); });