Орм sequelize
Второй день не могу понять почему у меня не проходит связь много ко многим и выдает ошибку
EagerLoadingError [SequelizeEagerLoadingError]: hints is not associated to hints_sections!
const { sequelize, Sequelize } = require('./database');
const Hints = sequelize.define(
'hints',
{
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false,
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
},
content: {
type: Sequelize.STRING(5000),
allowNull: false,
},
user_id: {
type: Sequelize.INTEGER,
references: {
model: 'users',
key: 'id'
},
allowNull: false,
},
},{
timestamps: false,
});
const Sections = sequelize.define(
'sections',
{
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false,
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
},
parent_id: {
type: Sequelize.INTEGER,
references: {
model: 'sections',
key: 'id'
},
allowNull: true,
},
position: {
type: Sequelize.INTEGER,
allowNull: true,
},
},{
timestamps: false,
});
const HintsSections = sequelize.define(
'hints_sections',
{
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false,
},
hint_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: Hints,
key: 'id'
},
},
section_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: Sections,
key: 'id'
},
},
},
{
timestamps: false,
freezeTableName: true,
});
Hints.belongsToMany(Sections, { through: HintsSections, foreignKey: 'hint_id' });
Sections.belongsToMany(Hints, { through: HintsSections, foreignKey: 'section_id' });
async function init() {
await sequelize.sync().then(async (result) => {
const response = await Roles.findAll({});
await HintsSections.findAll({
where: { section_id: 1 },
include: {
model: Hints
}
});
if(response.length < 3) {
Roles.create({ title: 'admin' });
Roles.create({ title: 'moderator' });
Roles.create({ title: 'user' });
}
});
}
init();
Пробовал из HintsSections убирать references, пробовал в HintsSections переносить связь - постоянно одна и та же ошибка, как быть?