The official documentation only deals with sample code which defines two separate models followed by association / relation code as follows.
var User = this.sequelize.define('user', {/* attributes */})
, Company = this.sequelize.define('company', {/* attributes */});
User.belongsTo(Company); // Will add companyId to user
My guesses are
- Require all of the models and define associations in a separate file, then require that file from, say,
app.js. - In each Model file, require needed models and define associations in
classMethods.associate(models).
and I can't really decide which one is a "right" way. I'm using Sequelize-CLI to generate migration files and model files.