Allows connector property to be a string

This commit is contained in:
Raymond Feng 2013-07-30 10:52:30 -07:00
parent 3051f0457f
commit 7ce6cfc9ab
1 changed files with 11 additions and 6 deletions

View File

@ -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() {