Есть две таблцы:
let Cases = sequelize.define('cases', {
title: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
category: {
type: DataTypes.INTEGER,
allowNull: false,
},
img: {
type: DataTypes.STRING,
allowNull: false,
},
price: {
type: DataTypes.INTEGER,
allowNull: false
},
oldPrice: {
type: DataTypes.INTEGER
},
counter: {
type: DataTypes.INTEGER,
},
totalCounter: {
type: DataTypes.INTEGER,
}
}, {
timestamps: false
});
let Categories = sequelize.define('categories', {
title: {
type: DataTypes.STRING,
allowNull: false
}
}, {
timestamps: false
});
Мне нужно выполнить такой запрос:
SELECT cases.*, casecategories.title AS `cat` FROM cases LEFT JOIN casecategories ON cases.category = casecategories.id;
Делаю такие ассоциации и запрос:
models.categories.hasMany(models.cases, {foreignKey: 'category'});
models.cases.belongsTo(models.categories, {foreignKey: 'id'});
const cases2 = await models.cases.findAll({
raw: true,
include: [
{ model: models.categories, attributes: ['title'] }
],
});
Однако получаю ошибку:
Error: Naming collision between attribute 'category' and association 'category' on model cases. To remedy this, change either foreignKey or as in your association definition
Что не так?