Create proxy methods for aliases

This commit is contained in:
Simon Ho 2015-03-26 17:14:35 -07:00
parent e5e114622a
commit 2b3f5171fe
2 changed files with 21 additions and 1 deletions

View File

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

View File

@ -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);
});
});
});