From 7ce6cfc9abc6c48e5eed2129e16cea07907cb610 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 30 Jul 2013 10:52:30 -0700 Subject: [PATCH] Allows connector property to be a string --- lib/datasource.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/datasource.js b/lib/datasource.js index cd391d84..fde1e7ce 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -152,11 +152,9 @@ DataSource.prototype.setup = function(name, settings) { var connector; // support single settings object - if(name && typeof name === 'object') { - if(!name.initialize) { + if(name && typeof name === 'object' && !settings) { settings = name; name = undefined; - } } if(typeof settings === 'object') { @@ -164,8 +162,8 @@ DataSource.prototype.setup = function(name, settings) { connector = settings; } else if(settings.connector) { connector = settings.connector; - } else if(settings.connector) { - connector = settings.connector; + } else if(settings.adapter) { + connector = settings.adapter; } } @@ -193,13 +191,20 @@ DataSource.prototype.setup = function(name, settings) { } else { // try foreign connector try { - connector = require('loopback-connector-' + name); + if(name.indexOf('loopback-connector-') === -1) { + name = 'loopback-connector-' + name; + } + connector = require(name); } catch (e) { return console.log('\nWARNING: LoopbackData connector "' + name + '" is not installed,\nso your models would not work, to fix run:\n\n npm install loopback-connector-' + name, '\n'); } } } + if('string' === typeof connector) { + connector = require(connector); + } + if (connector) { var postInit = function postInit() {