npm run start
Erro :
C:\orm-sequelize\node_modules\sequelize\lib\associations\mixin.js:13
throw new Error(${this.name}.hasMany called with something that's not a subclass of Sequelize.Model
);
^
Error: Niveis.hasMany called with something that's not a subclass of Sequelize.Model at Niveis.hasMany (C:\orm-sequelize\node_modules\sequelize\lib\associations\mixin.js:13:13) at Niveis.associate (C:\orm-sequelize\api\models\niveis.js:14:14) at C:\orm-sequelize\api\models\index.js:31:19 at Array.forEach () at Object. (C:\orm-sequelize\api\models\index.js:29:17) at Module.compile (node:internal/modules/cjs/loader:1159:14) at Module.extensions..js (node:internal/modules/cjs/loader:1213:10) at Module.load (node:internal/modules/cjs/loader:1037:32) at Module._load (node:internal/modules/cjs/loader:878:12) at Module.require (node:internal/modules/cjs/loader:1061:19)
Node.js v18.12.1
Arquivo niveis.js da pasta models:
'use strict'; const { Model } = require('sequelize'); module.exports = (sequelize, DataTypes) => { class Niveis extends Model { /**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
Niveis.hasMany(models.Turmas, {
foreignKey: 'nivel_id'
});
}
} Niveis.init({ descr_nivel: DataTypes.STRING }, { sequelize, modelName: 'Niveis', }); return Niveis; };
--- Obs: ocorreu também quando usa o belongsTo