Fix the model attachment to data source

This commit is contained in:
Raymond Feng 2013-11-19 10:49:54 -08:00
parent 6eb7f1939c
commit 2bcdea76f5
1 changed files with 10 additions and 13 deletions

View File

@ -548,26 +548,23 @@ DataSource.prototype.getModelDefinition = function(name) {
DataSource.prototype.attach = function (modelClass) {
if(modelClass.dataSource === this) {
// Already attached to the data source
return;
return modelClass;
}
if(modelClass.modelBuilder !== this.modelBuilder) {
this.modelBuilder.definitions[modelClass.modelName] = modelClass.definition;
this.modelBuilder.models[modelClass.modelName] = modelClass;
// reset the modelBuilder
modelClass.modelBuilder = this.modelBuilder;
}
var className = modelClass.modelName;
var modelDef = modelClass.modelBuilder.getModelDefinition(className);
var properties = modelDef.properties;
var settings = modelDef.settings;
// redefine the dataSource
modelClass.dataSource = this;
// add to def
var def = new ModelDefinition(this.modelBuilder, className, properties, settings);
def.build();
this.modelBuilder.definitions[className] = def;
this.modelBuilder.models[className] = modelClass;
this.setupDataAccess(modelClass, settings);
this.setupDataAccess(modelClass, modelClass.settings);
modelClass.emit('dataSourceAttached', modelClass);
return modelClass;
return this;
};
/**