diff --git a/lib/relation-definition.js b/lib/relation-definition.js index 3b93763f..e608a338 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -189,10 +189,11 @@ RelationDefinition.prototype.applyScope = function(modelInstance, filter) { filter.where[discriminator] = this.modelFrom.modelName; } } + var scope; if (typeof this.scope === 'function') { - var scope = this.scope.call(this, modelInstance, filter); + scope = this.scope.call(this, modelInstance, filter); } else { - var scope = this.scope; + scope = this.scope; } if (typeof scope === 'object') { mergeQuery(filter, scope); @@ -207,25 +208,27 @@ RelationDefinition.prototype.applyScope = function(modelInstance, filter) { RelationDefinition.prototype.applyProperties = function(modelInstance, obj) { var source = modelInstance, target = obj; if (this.options.invertProperties) { - source = obj, target = modelInstance; + source = obj; + target = modelInstance; } if (this.options.embedsProperties) { target = target.__data[this.name] = {}; target[this.keyTo] = source[this.keyTo]; } + var k, key; if (typeof this.properties === 'function') { var data = this.properties.call(this, source, target); - for(var k in data) { + for(k in data) { target[k] = data[k]; } } else if (Array.isArray(this.properties)) { - for(var k = 0; k < this.properties.length; k++) { - var key = this.properties[k]; + for(k = 0; k < this.properties.length; k++) { + key = this.properties[k]; target[key] = source[key]; } } else if (typeof this.properties === 'object') { - for(var k in this.properties) { - var key = this.properties[k]; + for(k in this.properties) { + key = this.properties[k]; target[key] = source[k]; } }