From 2f575482c036483b10d9fd023dd3447307c8d25f Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Sat, 5 Oct 2013 10:53:13 -0700 Subject: [PATCH] Code clean up --- lib/model-definition.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/model-definition.js b/lib/model-definition.js index bb45fdf1..c141fdb8 100644 --- a/lib/model-definition.js +++ b/lib/model-definition.js @@ -233,10 +233,6 @@ ModelDefinition.prototype.resolveType = function(type) { } else { return this.modelBuilder.define(this.modelBuilder.getSchemaName(null), type, {anonymous: true, idInjection: false}); - /* - console.error(type); - throw new Error('Missing type property'); - */ } } else if('function' === typeof type ) { return type; @@ -259,22 +255,19 @@ ModelDefinition.prototype.build = function (forceRebuild) { } this.properties = {}; for (var p in this.rawProperties) { - var type = this.resolveType(this.rawProperties[p]); + var prop = this.rawProperties[p]; + var type = this.resolveType(prop); if (typeof type === 'string') { - if (Array.isArray(this.associations)) { - this.associations.push({ - source: this.name, - target: type, - relation: Array.isArray(this.rawProperties[p]) ? 'hasMany' : 'belongsTo', - as: p - }); - // delete this.rawProperties[p]; - } + this.associations.push({ + source: this.name, + target: type, + relation: Array.isArray(prop) ? 'hasMany' : 'belongsTo', + as: p + }); } else { var typeDef = { type: type }; - var prop = this.rawProperties[p]; if (typeof prop === 'object' && prop !== null) { for (var a in prop) { // Skip the type property but don't delete it Model.extend() shares same instances of the properties from the base class