I am just creating or updating a table having a Many-to-Many association with another table like here: Company <-> Industry <-> CompanyIndustryRelation.
Industry.js
'use strict';
module.exports = (sequelize, DataTypes) => {
const Industry = sequelize.define('Industry', {
industry_name: DataTypes.STRING,
}, {
timestamps: false,
underscored: true,
tableName: 'industry',
});
Industry.associate = function(models) {
Industry.belongsToMany(models.Company, {
through: 'company_industry_relation', foreignkey: 'industry_id'
});
};
return Industry;
};
Company.js
'use strict';
module.exports = (sequelize, DataTypes) => {
const Company = sequelize.define('Company', {
company_name: DataTypes.STRING,
}, {
timestamps: false,
underscored: true,
tableName: 'company',
});
Company.associate = function(models) {
Company.belongsToMany(models.Industry, {
through: 'company_industry_relation', foreignKey: 'company_id'
});
};
return Company;
};
CompanyIndustryRelation.js
'use strict';
module.exports = (sequelize, DataTypes) => {
const CompanyIndustryRelation = sequelize.define('CompanyIndustryRelation', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
},
}, {
timestamps: false,
underscored: true,
tableName: 'company_industry_relation',
});
return CompanyIndustryRelation;
};
Currently I have the industry table already built like down below.

Industry array industry = [ { label: 'Accounting' }, { label: 'Computer Science' } ]
CompanyName: 'ApolloIT'
I want to create a new company record with the given industry array and companyName.
Thanks in advance!
Company -> CompanyIndustryRelation <- Industry. It's not clear what you want to create or update.for (const i of industry) { const industryInstance = await Industry.findOne({ industry_name: i.label }); await CompanyIndustryRelation.create({ company_id: company.id, industry_id: industryInstance.id }); }But it's saying error"id" of relation "company_industry_relation" does not exist