Fix minor autoWiring bugs
This commit is contained in:
parent
3753c15b71
commit
aaa8423257
|
@ -221,8 +221,16 @@ app.boot = function(options) {
|
||||||
app.model(key, obj);
|
app.model(key, obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
// attach models to dataSources by type
|
// try to attach models to dataSources by type
|
||||||
loopback.autoAttach();
|
try {
|
||||||
|
require('./loopback').autoAttach();
|
||||||
|
} catch(e) {
|
||||||
|
if(e.name === 'AssertionError') {
|
||||||
|
console.warn(e);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// require directories
|
// require directories
|
||||||
var requiredModels = requireDir(path.join(appRootDir, 'models'));
|
var requiredModels = requireDir(path.join(appRootDir, 'models'));
|
||||||
|
|
|
@ -97,8 +97,8 @@ loopback.createDataSource = function (name, options) {
|
||||||
return ModelCtor;
|
return ModelCtor;
|
||||||
};
|
};
|
||||||
|
|
||||||
if(options && options.defaultForType) {
|
if(ds.settings && ds.settings.defaultForType) {
|
||||||
loopback.setDefaultDataSourceForType(options.defaultForType, ds);
|
loopback.setDefaultDataSourceForType(ds.settings.defaultForType, ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ds;
|
return ds;
|
||||||
|
@ -116,7 +116,9 @@ loopback.createModel = function (name, properties, options) {
|
||||||
var model = loopback.Model.extend(name, properties, options);
|
var model = loopback.Model.extend(name, properties, options);
|
||||||
|
|
||||||
// try to attach
|
// try to attach
|
||||||
loopback.autoAttachModel(model);
|
try {
|
||||||
|
loopback.autoAttachModel(model);
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -228,8 +230,9 @@ loopback.autoAttachModel = function(ModelCtor) {
|
||||||
if(ModelCtor.autoAttach) {
|
if(ModelCtor.autoAttach) {
|
||||||
var ds = loopback.getDefaultDataSourceForType(ModelCtor.autoAttach);
|
var ds = loopback.getDefaultDataSourceForType(ModelCtor.autoAttach);
|
||||||
|
|
||||||
assert(ds instanceof DataSource, 'cannot autoAttach model "' + ModelCtor.modelName
|
assert(ds instanceof DataSource, 'cannot autoAttach model "'
|
||||||
+ '". No dataSource found of type ' + ModelCtor.attachTo);
|
+ ModelCtor.modelName
|
||||||
|
+ '". No dataSource found of type ' + ModelCtor.autoAttach);
|
||||||
|
|
||||||
ModelCtor.attachTo(ds);
|
ModelCtor.attachTo(ds);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue