Merge pull request #56 from strongloop/scope-remoting
Remove the proxy as it is now handled by the juggler
This commit is contained in:
commit
3a8369a8ab
|
@ -94,54 +94,10 @@ loopback.createDataSource = function (name, options) {
|
||||||
ds.createModel = function (name, properties, settings) {
|
ds.createModel = function (name, properties, settings) {
|
||||||
var ModelCtor = loopback.createModel(name, properties, settings);
|
var ModelCtor = loopback.createModel(name, properties, settings);
|
||||||
ModelCtor.attachTo(ds);
|
ModelCtor.attachTo(ds);
|
||||||
|
|
||||||
var hasMany = ModelCtor.hasMany;
|
|
||||||
|
|
||||||
if(hasMany) {
|
|
||||||
ModelCtor.hasMany = function (anotherClass, params) {
|
|
||||||
var origArgs = arguments;
|
|
||||||
var thisClass = this, thisClassName = this.modelName;
|
|
||||||
params = params || {};
|
|
||||||
if (typeof anotherClass === 'string') {
|
|
||||||
params.as = anotherClass;
|
|
||||||
if (params.model) {
|
|
||||||
anotherClass = params.model;
|
|
||||||
} else {
|
|
||||||
var anotherClassName = i8n.singularize(anotherClass).toLowerCase();
|
|
||||||
for(var name in this.schema.models) {
|
|
||||||
if (name.toLowerCase() === anotherClassName) {
|
|
||||||
anotherClass = this.schema.models[name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var pluralized = anotherClass.pluralModelName || i8n.pluralize(anotherClass.modelName);
|
|
||||||
var methodName = params.as || i8n.camelize(i8n.pluralize(anotherClass.modelName), true);
|
|
||||||
var proxyMethodName = 'get' + i8n.titleize(pluralized, true);
|
|
||||||
|
|
||||||
// create a proxy method
|
|
||||||
var fn = this.prototype[proxyMethodName] = function () {
|
|
||||||
// this[methodName] cannot be a shared method
|
|
||||||
// because it is defined inside
|
|
||||||
// a property getter...
|
|
||||||
|
|
||||||
var f = (this[methodName] || this[pluralized]);
|
|
||||||
f.apply(thisClass, arguments);
|
|
||||||
};
|
|
||||||
|
|
||||||
fn.shared = true;
|
|
||||||
fn.http = {verb: 'get', path: '/' + pluralized};
|
|
||||||
fn.accepts = {arg: 'where', type: 'object'};
|
|
||||||
fn.returns = {root: true};
|
|
||||||
hasMany.apply(this, arguments);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return ModelCtor;
|
return ModelCtor;
|
||||||
}
|
};
|
||||||
return ds;
|
return ds;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a named vanilla JavaScript class constructor with an attached set of properties and options.
|
* Create a named vanilla JavaScript class constructor with an attached set of properties and options.
|
||||||
|
|
Loading…
Reference in New Issue