Fix the remote delegation

This commit is contained in:
Raymond Feng 2013-12-20 17:28:21 -08:00
parent 1f965bfedb
commit f1773857bb
2 changed files with 9 additions and 10 deletions

View File

@ -26,7 +26,7 @@ Relation.relationNameFor = function relationNameFor(foreignKey) {
* @example `User.hasMany(Post, {as: 'posts', foreignKey: 'authorId'});`
*/
Relation.hasMany = function hasMany(anotherClass, params) {
var thisClass = this, thisClassName = this.modelName;
var thisClassName = this.modelName;
params = params || {};
if (typeof anotherClass === 'string') {
params.as = anotherClass;
@ -71,7 +71,6 @@ Relation.hasMany = function hasMany(anotherClass, params) {
done = function() {};
}
var self = this;
var id = this[idName];
anotherClass.create(data, function(err, ac) {
if (err) return done(err, ac);
var d = {};
@ -98,7 +97,6 @@ Relation.hasMany = function hasMany(anotherClass, params) {
params.through.findOrCreate({where: query}, data, done);
};
scopeMethods.remove = function(acInst, done) {
var self = this;
var q = {};
q[fk2] = acInst[idName] || acInst;
params.through.findOne({where: q}, function(err, d) {

View File

@ -60,6 +60,7 @@ function defineScope(cls, targetClass, name, params, methods) {
}
};
f._scope = typeof params === 'function' ? params.call(this) : params;
f.build = build;
f.create = create;
f.destroyAll = destroyAll;
@ -83,8 +84,8 @@ function defineScope(cls, targetClass, name, params, methods) {
// Wrap the property into a function for remoting
var fn = function() {
var f = cls[name];
f.apply(cls, arguments);
var f = this[name];
f.apply(this[name], arguments);
};
fn.shared = true;
@ -96,21 +97,21 @@ function defineScope(cls, targetClass, name, params, methods) {
cls['__get__' + name] = fn;
var fn_create = function() {
var f = cls[name].create;
f.apply(cls[name], arguments);
var f = this[name].create;
f.apply(this[name], arguments);
};
fn_create.shared = true;
fn_create.http = {verb: 'post', path: '/' + name};
fn_create.accepts = {arg: 'data', type: 'object', source: 'body'};
fn_create.accepts = {arg: 'data', type: 'object', http: {source: 'body'}};
fn_create.description = 'Creates ' + name;
fn_create.returns = {arg: 'data', type: 'object', root: true};
cls['__create__' + name] = fn_create;
var fn_delete = function() {
var f = cls[name].destroyAll;
f.apply(cls[name], arguments);
var f = this[name].destroyAll;
f.apply(this[name], arguments);
};
fn_delete.shared = true;
fn_delete.http = {verb: 'delete', path: '/' + name};