Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove sequelize.import helper #12175

Merged
merged 1 commit into from
Apr 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/manual/other-topics/upgrade-to-v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ You should now use [cls-hooked](https://github.com/Jeff-Lewis/cls-hooked) packag
Sequelize.useCLS(namespace);
```

### Promise
### Sequelize

Bluebird has been removed. Public API now returns native promises. `Sequelize.Promise` is no longer available.
- Bluebird has been removed. Public API now returns native promises.
- `Sequelize.Promise` is no longer available.
- `sequelize.import` method has been removed.

### Model

Expand Down
34 changes: 0 additions & 34 deletions lib/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ class Sequelize {
this.modelManager = new ModelManager(this);
this.connectionManager = this.dialect.connectionManager;

this.importCache = {};

Sequelize.runHooks('afterInit', this);
}

Expand Down Expand Up @@ -462,38 +460,6 @@ class Sequelize {
return !!this.modelManager.models.find(model => model.name === modelName);
}

/**
* Imports a model defined in another file. Imported models are cached, so multiple
* calls to import with the same path will not load the file multiple times.
*
* @tutorial https://github.com/sequelize/express-example
*
* @param {string} importPath The path to the file that holds the model you want to import. If the part is relative, it will be resolved relatively to the calling file
*
* @returns {Model} Imported model, returned from cache if was already imported
*/
import(importPath) {
// is it a relative path?
if (path.normalize(importPath) !== path.resolve(importPath)) {
// make path relative to the caller
const callerFilename = Utils.stack()[1].getFileName();
const callerPath = path.dirname(callerFilename);

importPath = path.resolve(callerPath, importPath);
}

if (!this.importCache[importPath]) {
let defineCall = arguments.length > 1 ? arguments[1] : require(importPath);
if (typeof defineCall === 'object') {
// ES6 module compatibility
defineCall = defineCall.default;
}
this.importCache[importPath] = defineCall(this, DataTypes);
}

return this.importCache[importPath];
}

/**
* Execute a query on the DB, optionally bypassing all the Sequelize goodness.
*
Expand Down
22 changes: 0 additions & 22 deletions test/integration/sequelize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1224,28 +1224,6 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
});
});

describe('import', () => {
it('imports a dao definition from a file absolute path', function() {
const Project = this.sequelize.import('assets/project');
expect(Project).to.exist;
});

it('imports a dao definition with a default export', function() {
const Project = this.sequelize.import('assets/es6project');
expect(Project).to.exist;
});

it('imports a dao definition from a function', function() {
const Project = this.sequelize.import('Project', (sequelize, DataTypes) => {
return sequelize.define(`Project${parseInt(Math.random() * 9999999999999999, 10)}`, {
name: DataTypes.STRING
});
});

expect(Project).to.exist;
});
});

describe('define', () => {
it('raises an error if no values are defined', function() {
expect(() => {
Expand Down