gpt4 book ai didi

sequelize.js - 别名关联必须具有唯一的别名

转载 作者:行者123 更新时间:2023-12-03 22:34:58 25 4
gpt4 key购买 nike

根据有关在 pairs 中创建关联并使用 multiple associations on the same model 的文档,我收到错误

"You have used the alias author in two separate associations. Aliased associations must have unique aliases."



我的作者协会是;
User.hasMany(CourseRequest, {
as: 'author',
foreignKey: {
name: 'authorId',
type: Sequelize.UUID,
allowNull: false,
validate: {
isUUID: {
args: 4,
msg: `author must be a valid ID`,
},
notNull: {
msg: `author is required`,
},
},
},
});

CourseRequest.belongsTo(User, {
as: 'author',
foreignKey: {
name: 'authorId',
type: Sequelize.UUID,
allowNull: false,
validate: {
isUUID: {
args: 4,
msg: `author must be a valid ID`,
},
notNull: {
msg: `author is required`,
},
},
},
});

我该如何解决这个问题?

最佳答案

我设法解决了这个问题。我最初正在调用一个函数,其中模型被用作

require('foo').bar()

代替
const {bar} = require('foo'); 
bar();

关于sequelize.js - 别名关联必须具有唯一的别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61900290/

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