From 43993bf97598c659d21eff66158c053265b403a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 9 Jun 2014 16:31:43 +0200 Subject: [PATCH] Remove auto-attach. Breaking change. The bootstrapper no longer calls `loopback.autoAttach`. Applications have to explicitly configure datasources for their models via `models.json`. --- docs/configuration.md | 15 +++++++++++++++ lib/executor.js | 14 -------------- test/executor.test.js | 11 +++++++++++ test/global-setup.js | 11 ----------- 4 files changed, 26 insertions(+), 25 deletions(-) delete mode 100644 test/global-setup.js diff --git a/docs/configuration.md b/docs/configuration.md index 18dc878..270afa6 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -154,3 +154,18 @@ All code samples are referring to the sample project described above. var app = loopback(); boot(app, __dirname); ``` + +#### Attaching built-in models + +Models provided by LoopBack, such as `User` or `Role`, are no longer +automatically attached to default data-sources. The data-source configuration +entry `defaultForType` is silently ignored. + +You have to explicitly configure all built-in models used by your application +in the `models.json` file. + +``` +{ + "Role": { "dataSource": "db" } +} +``` diff --git a/lib/executor.js b/lib/executor.js index 81f5a40..b7332d2 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -20,7 +20,6 @@ module.exports = function execute(app, instructions) { setupDataSources(app, instructions); setupModels(app, instructions); - autoAttach(); runBootScripts(app, instructions); @@ -135,19 +134,6 @@ function tryRequire(modulePath) { } } -// Deprecated, will be removed soon -function autoAttach() { - try { - loopback.autoAttach(); - } catch(e) { - if(e.name === 'AssertionError') { - console.warn(e); - } else { - throw e; - } - } -} - function runBootScripts(app, instructions) { runScripts(app, instructions.files.boot); } diff --git a/test/executor.test.js b/test/executor.test.js index bf86562..f5c27f8 100644 --- a/test/executor.test.js +++ b/test/executor.test.js @@ -68,6 +68,17 @@ describe('executor', function() { assert(app.dataSources.TheDb); }); + it('does not call autoAttach', function() { + boot.execute(app, dummyInstructions); + + // loopback-datasource-juggler quirk: + // Model.dataSources has modelBuilder as the default value, + // therefore it's not enough to assert a false-y value + var actual = loopback.Email.dataSource instanceof loopback.DataSource ? + 'attached' : 'not attached'; + expect(actual).to.equal('not attached'); + }); + describe('with boot and models files', function() { beforeEach(function() { boot.execute(app, simpleAppInstructions()); diff --git a/test/global-setup.js b/test/global-setup.js deleted file mode 100644 index 1152607..0000000 --- a/test/global-setup.js +++ /dev/null @@ -1,11 +0,0 @@ -var loopback = require('loopback'); - -// bootLoopBackApp() calls loopback.autoAttach -// which attempts to attach all models to default datasources -// one of those models is Email which requires 'email' datasource -loopback.setDefaultDataSourceForType('mail', { - connector: loopback.Mail, - transports: [ - {type: 'STUB'} - ] -});