我有两个表,Roles
和Users
。现在查Users
表的时候想LEFT JOIN
Roles
表,我用了以下代码:
include: [
{
association: model.Users.hasOne(model.Roles, {
foreignKey: 'id',
as: 'UserRoles',
}),
},
]
然后第一次请求没有问题,之后再请求同一个接口就报错了
stack: SequelizeAssociationError: You have used the alias UserRoles in two separate associations. Aliased associations must have unique aliases.
重名原因不太清楚,但是
as
字段的值加上时间戳即可