Well, as you can see, two things are needed to determine your model:
- Sequelize or DataTypes
- sequelize
In the first example, when using sequelize.import('something'); it is like using require('something')(this, Sequelize); (this is an instance of sequelize)
Both are necessary to initialize your model, but it is important to understand: one of them is classtype, therefore it is global, the other is an instance and must be created with your connection parameters.
So if you do this:
var Project = sequelize.define("Project", { name: Sequelize.STRING, description: Sequelize.TEXT }); module.exports = Project
Where did sexualization come from? It must be created and transmitted in some way.
Here is an example with a requirement, not an import:
// /path/to/app.js var Sequelize = require('sequelize'); var sequelize = new Sequelize(/* ... */); var Project = require('/path/to/models/project')(sequelize, Sequelize); // /path/to/models/project.js module.exports = function (sequelize, DataTypes) { sequelize.define("Project", { name: DataTypes.STRING, description: DataTypes.TEXT }); }; module.exports = Project
You can even change it so you donβt have to pass Sequelize, requiring it in the model itself, but you still need to create a sequelize instance before defining the model.
source share