sequelize.js - Sequelize error model is not associated -
i have 2 models: userauth , userfollow associate before sync. association userfollow has 2 foreign keys referencing user. did not use aliases when do:
userauth.findone({ where:{ id: "someid" }, include: [{ model: userfollow }], logging: false })
it throws error says: [error: user_follow not associated user_auth!]
i have class method "associate" in userfollow call before sync:
classmethods: { associate: function(models) { // alter table user_follow // add foreign key (follower_id) // references user_auth(id) // on delete cascade // on update cascade userfollow.belongsto(models.user_auth, { ondelete: "cascade", onupdate: "cascade", foreignkey: 'follower_id', targetkey: 'id' }); // alter table user_follow // add foreign key (follower_id) // references user_auth(id) // on delete cascade // on update cascade userfollow.belongsto(models.user_auth, { ondelete: "cascade", onupdate: "cascade", foreignkey: 'followee_id', targetkey: 'id' }); } },
Comments
Post a Comment