Make sure model definition is built when attaching to a DS

This commit is contained in:
Raymond Feng 2013-10-11 16:35:17 -07:00
parent a9cf0567ae
commit dd936b15a2
2 changed files with 12 additions and 12 deletions

View File

@ -412,9 +412,17 @@ DataSource.prototype.attach = function (ModelCtor) {
// Already attached to the data source // Already attached to the data source
return; return;
} }
var properties = ModelCtor.dataSource.definitions[ModelCtor.modelName].properties;
var settings = ModelCtor.dataSource.definitions[ModelCtor.modelName].settings;
var className = ModelCtor.modelName; var className = ModelCtor.modelName;
var properties = ModelCtor.dataSource.definitions[className].properties;
var settings = ModelCtor.dataSource.definitions[className].settings;
// redefine the dataSource
ModelCtor.dataSource = this;
// add to def
var def = new ModelDefinition(this, className, properties, settings);
def.build();
this.definitions[className] = def;
this.models[className] = ModelCtor;
this.mixin(ModelCtor); this.mixin(ModelCtor);
@ -427,15 +435,6 @@ DataSource.prototype.attach = function (ModelCtor) {
}); });
} }
// redefine the dataSource
hiddenProperty(ModelCtor, 'dataSource', this);
ModelCtor.dataSource = this;
// add to def
this.definitions[className] = new ModelDefinition(this, className, properties, settings);
this.models[className] = ModelCtor;
return this; return this;
}; };

View File

@ -41,6 +41,7 @@ function ModelDefinition(modelBuilder, name, properties, settings) {
} }
this.associations = []; this.associations = [];
this.properties = null; this.properties = null;
this.build();
} }
util.inherits(ModelDefinition, EventEmitter); util.inherits(ModelDefinition, EventEmitter);