diff --git a/lib/relation-definition.js b/lib/relation-definition.js index 7b90c18b..b9c298f8 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -64,12 +64,15 @@ function extendScopeMethods(definition, scopeMethods, ext) { if (typeof ext === 'function') { customMethods = ext.call(definition, scopeMethods, relationClass); } else if (typeof ext === 'object') { + function createFunc(definition, relationMethod) { + return function() { + var relation = new relationClass(definition, this); + return relationMethod.apply(relation, arguments); + }; + }; for (var key in ext) { var relationMethod = ext[key]; - var method = scopeMethods[key] = function () { - var relation = new relationClass(definition, this); - return relationMethod.apply(relation, arguments); - }; + var method = scopeMethods[key] = createFunc(definition, relationMethod); if (relationMethod.shared) { sharedMethod(definition, key, method, relationMethod); }