Just starting to use Sequelize, and I set up a bunch of models and seeds, but I canβt understand the links and associations. I do not see an example of use for links, even if they do what I think they do, but I could not find a good explanation in the docs.
Is it redundant, having links and associations?
module.exports = (sequelize, DataTypes) => { const UserTask = sequelize.define('UserTask', { id: { primaryKey: true, type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4 }, userId: { type: DataTypes.UUID, references: { // <--- is this redundant to associate model: 'User', key: 'id' } } // ... removed for brevity }, { classMethods: { associate: models => { <--- makes references redundant? UserTask.belongsTo(models.User, { onDelete: 'CASCADE', foreignKey: { fieldName: 'userId', allowNull: true, require: true }, targetKey: 'id' }); } } } ); return UserTask; };
source share