Code clean up

This commit is contained in:
Raymond Feng 2013-10-05 10:53:13 -07:00
parent 7f170a0542
commit 2f575482c0
1 changed files with 8 additions and 15 deletions

View File

@ -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