2

Im trying to create association between two tables using models that are generated by sequelize-cli. But it is not making the relations in db.

Model User

    User.hasMany(models.Albums, {
      foreignKey: 'user_id',
      as: 'userAlbums'
    });
  };

Model Album

Albums.associate = function(models) {
    // associations can be defined here
    Albums.belongsTo(models.User, {
      foreignKey: 'user_id',
      onDelete: 'cascade'
    });
  };

0 Answers0