I'm using sequelize v5.21 and sequelize-cli v5.5.1 for a MySQL database.
I'm currently trying to create some association 1:M under the following model generated code from the cli like so:
Where: a is the source and b the target.
model.associate = function (models) {
// associations can be defined here
a.hasOne(models.b);
}
and the other model, i have:
model.associate = function (models) {
// associations can be defined here
b.belongsTo(models.a);
}
Finally, im using this code to check the associations by creating a entries:
a.create({
...
}).then(a => {
return a.createB({
...,
}).catch(err => console.log(err));
}).catch(err => console.log(err)
);
In which i'm getting an error on the "a.createB()..." as is not a function...
So, i was curious enough and tried doing the associations right before checking the associations like so:
a.hasOne(b);
b.belongsTo(a);
In which works just fine...
My question is, is the "model.associate" property still working on the v5^?
Note: I have used the check associations method provided in the sequelize documentation but i prefer this one since it's easier to read.