From 1e3bfc6c182425e9c1286403d32b0c8406fc7f5f Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Fri, 1 Nov 2013 12:53:30 -0700 Subject: [PATCH] Automatically convert strings to connectors if they are LoopBack connectors --- lib/application.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/application.js b/lib/application.js index 61893d39..6aa89b52 100644 --- a/lib/application.js +++ b/lib/application.js @@ -73,6 +73,8 @@ app.model = function (Model, config) { this.models[classify(modelName)] = this.models[camelize(modelName)] = modelFromConfig(modelName, config, this); + this.model(Model); + return Model; } @@ -235,6 +237,19 @@ function camelize(str) { } 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); }