From ab791fc258806a8d9140aa2cc895b9acf8faf470 Mon Sep 17 00:00:00 2001 From: Kevin Scroggins Date: Fri, 15 Dec 2017 17:32:22 -0500 Subject: [PATCH] fix: preserve datasource name Modify the code creating juggler DataSource objects to correctly forward the datasource name provided by the user. --- lib/application.js | 12 ++++++------ test/app.test.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/application.js b/lib/application.js index 2a46c5ff..fc2c1462 100644 --- a/lib/application.js +++ b/lib/application.js @@ -505,21 +505,21 @@ function dataSourcesFromConfig(name, config, connectorRegistry, registry) { 'can not create data source without config object'); if (typeof config.connector === 'string') { - name = config.connector; - if (connectorRegistry[name]) { - config.connector = connectorRegistry[name]; + const connectorName = config.connector; + if (connectorRegistry[connectorName]) { + config.connector = connectorRegistry[connectorName]; } else { - connectorPath = path.join(__dirname, 'connectors', name + '.js'); + connectorPath = path.join(__dirname, 'connectors', connectorName + '.js'); if (fs.existsSync(connectorPath)) { config.connector = require(connectorPath); } } if (config.connector && typeof config.connector === 'object' && !config.connector.name) - config.connector.name = name; + config.connector.name = connectorName; } - return registry.createDataSource(config); + return registry.createDataSource(name, config); } function configureModel(ModelCtor, config, app) { diff --git a/test/app.test.js b/test/app.test.js index f32843a4..c964fbdf 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -787,7 +787,7 @@ describe('app', function() { it('looks up the connector in `app.connectors`', function() { app.connector('custom', loopback.Memory); app.dataSource('custom', {connector: 'custom'}); - expect(app.dataSources.custom.name).to.equal(loopback.Memory.name); + expect(app.dataSources.custom.name).to.equal('custom'); }); it('adds data source name to error messages', function() {