Correctly handle remoting of scope methods
This commit is contained in:
parent
af0ca5b108
commit
090c738bb5
|
@ -64,11 +64,18 @@ function extendScopeMethods(definition, scopeMethods, ext) {
|
|||
customMethods = ext.call(definition, scopeMethods, relationClass);
|
||||
} else if (typeof ext === 'object') {
|
||||
for (var key in ext) {
|
||||
scopeMethods[key] = function () {
|
||||
var relationMethod = ext[key];
|
||||
var method = scopeMethods[key] = function () {
|
||||
var relation = new relationClass(definition, this);
|
||||
return ext[key].apply(relation, arguments);
|
||||
return relationMethod.apply(relation, arguments);
|
||||
};
|
||||
if (ext[key].shared === true) scopeMethods[key].shared = true;
|
||||
if (relationMethod.shared) {
|
||||
method.shared = true;
|
||||
method.accepts = relationMethod.accepts;
|
||||
method.returns = relationMethod.returns;
|
||||
method.http = relationMethod.http;
|
||||
method.description = relationMethod.description;
|
||||
}
|
||||
customMethods.push(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1861,12 +1861,15 @@ describe('relations', function () {
|
|||
};
|
||||
|
||||
reverse.shared = true; // remoting
|
||||
reverse.http = { verb: 'put', path: '/products/reverse' };
|
||||
|
||||
Category.referencesMany(Product, { scopeMethods: {
|
||||
reverse: reverse
|
||||
} });
|
||||
|
||||
Category.prototype['__reverse__products'].should.be.a.function;
|
||||
should.exist(Category.prototype['__reverse__products'].shared);
|
||||
Category.prototype['__reverse__products'].http.should.eql(reverse.http);
|
||||
|
||||
db.automigrate(done);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue