Closed Orinameh closed 5 years ago
@Orinameh you should use the book's version of sequelize, because the new version will break in this part. Take a look: http://docs.sequelizejs.com/manual/tutorial/upgrade-to-v4.html
Yh, I also faced the same problem. I was able to install the book's version of sequelize, but for the sqlite3, the book's version ie 3.1.1 couldn't be installed. So I installed the current version which is 3.1.13. Things seem to be working for now, but I fear things might break in the subsequent chapters.
@ultrasamad im sticking to your opinion , i hope it doesnt break in the upcoming chapters. It is working now
Yh...If it does then there is no need uninstalling the current version, just maintain it but rather tweak the old codes to use the new codes of that version.
Hi there, This problem seems to me that the associate property is not being declared, if you not declare It in one of your models, do:
Object.keys(db.models).forEach(key =>{
if (db.models[key].hasOwnProperty('associate')){
db.models[key].associate(db.models);
}
});
Could you put the template code where you're giving the error?
Got the same problem, look like this works... for now :)
Object.keys(db.models).forEach(key => {
db.models[key].options.classMethods.associate(db.models);
});
I can confirm that the solution by @lvs-training works. I would definitely not recommend going back versions. It's better to update code accordingly but maybe have branches for situations where major differences occur in dependencies.
Entirely separately, but related, this also occurs with Jwt at one point. You can't do ExtractJwt.fromAuthHeader() anymore. (This is in auth.js.) Instead you have to do ExtractJwt.fromAuthHeaderWithScheme("jwt").
So even if not different branches, perhaps just updating the README with known discrepancies for dependency updates might be worthwhile. So far the one listed here and the one I just brought up are the only functional ones I've encountered. There is another issue where you might want to add "operatorAliases: false" to config.js to handle a deprecation warning with Sequelize.
Use ES6 classes with Sequelize 4
Model.associate = function (models) {
Tasks.belongsTo(models.Users);
};
Guys, many changes happened in the Sequelize module, unfortunatelly I can't update the book, so you have to use the right (old) versions of all modules in the book to the project runs fine.
Ok guys, so I've faced the same problem and this is the solution:
OLD const Users = sequelize.define('Users', { ... }, { classMethods: { associate: (models) => { Users.hasMany(models.Tasks); }, isPassword: (encodedPassword, password) => { return bcrypt.compareSync(password, encodedPassword); } });
NEW remove the classMethods object and place the following after:
Users.associate = function (models) { Users.hasMany(models.Tasks); };
Users.isPassword = function(encodedPassword, password) { return bcrypt.compareSync(password, encodedPassword); }
return Users;
this book is an amazing piece of work, hope you all enjoy it :)
Hi, thanks for your book. I have been battling with this error
TypeError: db.models[key].associate is not a function
. I have tried to resolve but all to no avail. Can you help out?