Reputation: 53
Dependency chain: relationships -> users => relationships
The goal is for Relationships to have a user_one, user_two, and last_user action. The standard user_one, user_two relationship works fine, but when I try to add in the last_user_action with Relationships.hasOne() I'm getting a dependency chain error. Is there a quick fix for this?
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"
}
);
Upvotes: 1
Views: 2035
Reputation: 53
Users.hasMany(models.Relationships, { as: 'lastUserAction', foreignKey: 'last_user_action' });
instead of Relationships.hasOne()
Upvotes: 1