T
T
the5x2019-03-05 23:35:37
JavaScript
the5x, 2019-03-05 23:35:37

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;
};

post:
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;
};

Why after sequelize db:migrate in the table with categories in the post_id column there is an integer and a field if there is data in the post table?
5c7edd1ab0412458148671.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question