Remove auto-attach.
Breaking change. The bootstrapper no longer calls `loopback.autoAttach`. Applications have to explicitly configure datasources for their models via `models.json`.
This commit is contained in:
parent
47b5bb5f5c
commit
43993bf975
|
@ -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" }
|
||||
}
|
||||
```
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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'}
|
||||
]
|
||||
});
|
Loading…
Reference in New Issue