Fix the model attachment to data source
This commit is contained in:
parent
6eb7f1939c
commit
2bcdea76f5
|
@ -548,26 +548,23 @@ DataSource.prototype.getModelDefinition = function(name) {
|
||||||
DataSource.prototype.attach = function (modelClass) {
|
DataSource.prototype.attach = function (modelClass) {
|
||||||
if(modelClass.dataSource === this) {
|
if(modelClass.dataSource === this) {
|
||||||
// Already attached to the data source
|
// 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
|
// redefine the dataSource
|
||||||
modelClass.dataSource = this;
|
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);
|
modelClass.emit('dataSourceAttached', modelClass);
|
||||||
|
return modelClass;
|
||||||
|
|
||||||
return this;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue