Answer the question
In order to leave comments, you need to log in
Can't link tables via Sequelize, why?
There are two
category tables:
module.exports = (sequelize, DataTypes) => {
const category = sequelize.define('category', {
title: DataTypes.STRING,
}, {});
category.associate = function(models) {
category.hasMany(models.post, {
foreignKey: 'post_id',
as: 'articles'
});
};
return category;
};
module.exports = (sequelize, DataTypes) => {
const post = sequelize.define('post', {
title: DataTypes.STRING,
}, {});
post.associate = function(models) {
post.belongsTo(models.category, {
foreignKey: 'post_id'
});
};
return post;
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question