Automatically convert strings to connectors if they are LoopBack connectors

This commit is contained in:
Ritchie Martori 2013-11-01 12:53:30 -07:00
parent 6179476030
commit 1e3bfc6c18
1 changed files with 15 additions and 0 deletions

View File

@ -73,6 +73,8 @@ app.model = function (Model, config) {
this.models[classify(modelName)] = this.models[classify(modelName)] =
this.models[camelize(modelName)] = modelFromConfig(modelName, config, this); this.models[camelize(modelName)] = modelFromConfig(modelName, config, this);
this.model(Model);
return Model; return Model;
} }
@ -235,6 +237,19 @@ function camelize(str) {
} }
function dataSourcesFromConfig(config) { function dataSourcesFromConfig(config) {
var connectorPath;
assert(typeof config === 'object',
'cannont create data source without config object');
if(typeof config.connector === 'string') {
connectorPath = path.join(__dirname, 'connectors', config.connector+'.js');
if(fs.existsSync(connectorPath)) {
config.connector = require(connectorPath);
}
}
return require('./loopback').createDataSource(config); return require('./loopback').createDataSource(config);
} }