Merge pull request #3733 from nitro404/hotfix/retain-datasource-name
Fixe data sources not retaining the correct name value
This commit is contained in:
commit
60c9dd166b
|
@ -505,21 +505,21 @@ function dataSourcesFromConfig(name, config, connectorRegistry, registry) {
|
||||||
'can not create data source without config object');
|
'can not create data source without config object');
|
||||||
|
|
||||||
if (typeof config.connector === 'string') {
|
if (typeof config.connector === 'string') {
|
||||||
name = config.connector;
|
const connectorName = config.connector;
|
||||||
if (connectorRegistry[name]) {
|
if (connectorRegistry[connectorName]) {
|
||||||
config.connector = connectorRegistry[name];
|
config.connector = connectorRegistry[connectorName];
|
||||||
} else {
|
} else {
|
||||||
connectorPath = path.join(__dirname, 'connectors', name + '.js');
|
connectorPath = path.join(__dirname, 'connectors', connectorName + '.js');
|
||||||
|
|
||||||
if (fs.existsSync(connectorPath)) {
|
if (fs.existsSync(connectorPath)) {
|
||||||
config.connector = require(connectorPath);
|
config.connector = require(connectorPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.connector && typeof config.connector === 'object' && !config.connector.name)
|
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) {
|
function configureModel(ModelCtor, config, app) {
|
||||||
|
|
|
@ -787,7 +787,7 @@ describe('app', function() {
|
||||||
it('looks up the connector in `app.connectors`', function() {
|
it('looks up the connector in `app.connectors`', function() {
|
||||||
app.connector('custom', loopback.Memory);
|
app.connector('custom', loopback.Memory);
|
||||||
app.dataSource('custom', {connector: 'custom'});
|
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() {
|
it('adds data source name to error messages', function() {
|
||||||
|
|
Loading…
Reference in New Issue