Create proxy methods for aliases
This commit is contained in:
parent
e5e114622a
commit
2b3f5171fe
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue