gpt4 book ai didi

node.js - Sequelize : Cyclic dependency found

转载 作者:行者123 更新时间:2023-11-29 13:18:33 26 4
gpt4 key购买 nike

依赖链:关系 -> 用户 => 关系

目标是让关系具有 user_one、user_two 和 last_user 操作。标准的 user_one、user_two 关系工作正常,但是当我尝试使用 Relationships.hasOne() 添加 last_user_action 时,出现依赖链错误。有没有快速解决这个问题的方法?

var Relationships = sequelize.define(
"Relationships",
{
type: DataTypes.ENUM('block', 'follow', 'pending')
},
{
classMethods: {
associate: function(models) {
Relationships.hasOne(models.Users, { as: 'lastUserAction', foreignKey: 'last_user_action' });
}
},
tableName: "relationships"
}
);


var Users = sequelize.define(
"Users",
{
firstName: DataTypes.STRING
},
{
classMethods: {
associate: function(models) {
Users.belongsToMany(models.Users, { as: 'userRelationship', through: models.Relationships, foreignKey: 'user_one_id', otherKey: 'user_two_id' });
}
},
tableName: "users"
}
);

最佳答案

Users.hasMany(models.Relationships, { as: 'lastUserAction', foreignKey: 'last_user_action' });

而不是 Relationships.hasOne()

关于node.js - Sequelize : Cyclic dependency found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45557083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com