gpt4 book ai didi

javascript - 使用sequelize ownTo 和 hasOne 会导致超出最大调用堆栈大小

转载 作者:行者123 更新时间:2023-12-02 22:57:30 25 4
gpt4 key购买 nike

在我的Conversation模型中,我有:

    Conversation.hasOne(sequelize.import('./audio'), { constraints: false })

音频中,我有:

    Audio.belongsTo(sequelize.import('./conversation'))

要从另一个文件加载这些,我正在做:

    fs.readdirSync(`${__dirname}`).forEach((modelFile) => {
if (path.extname(modelFile) === '.js' && modelFile !== 'index.js') {
sequelize.import(`./${modelFile}`)
}
})

所以我不能保证订单。但是 {constraints: false} 不应该有任何循环依赖吗?

如果我删除 belongsTohasOne,那么一切都会正常工作(某种程度上)。如果我只有 belongsTo,那么我无法执行如下查询:

        return db.models.Conversation.findAll({
where: {
status: {
$notIn: ['ready', 'error']
}
},
include: [{
model: db.models.Audio
}]
})

它提示音频对话没有关联。理想情况下,我希望它们彼此相关。

顺便说一句,我正在使用 v4

最佳答案

参见示例:

const Player = this.sequelize.define('player', {/* attributes */});
const Team = this.sequelize.define('team', {/* attributes */});

Player.belongsTo(Team); // Will add a teamId attribute to Player to hold the primary key value for Team

就您而言:

const Audio = require("./audio");
Conversation.hasOne(Audio, { constraints: false });
const Conversation = require("./conversation");
Audio.belongsTo(Conversation);

关于javascript - 使用sequelize ownTo 和 hasOne 会导致超出最大调用堆栈大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57925425/

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