gpt4 book ai didi

javascript - Sequelize ,其中relation.attribute 等于

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

我有以下定义:

var Team = sequelize.define('academy_team', {
id: DataTypes.INTEGER,
name: DataTypes.STRING,
academy_id: DataTypes.INTEGER,
is_complete: DataTypes.INTEGER,
started: DataTypes.INTEGER
}, {
freezeTableName: true,
instanceMethods: {
startedTeams: function(onSuccess, onError) {
Team.findAll({
include: [{
all: true
}],
where: {
model: academy,
division_id: 19
}
}, {})
.ok(onSuccess).error(onError);
}
}
});

academy = sequelize.define('academy', {
id: DataTypes.INTEGER,
name: DataTypes.STRING,
organization_id: DataTypes.INTEGER,
division_id: DataTypes.INTEGER,
status_id: DataTypes.INTEGER
}, {
freezeTableName: true,
instanceMethods: {}
});

具有以下关系:
Team.belongsTo(academy, {foreignKey: 'academy_id'});

现在,从我的(失败)尝试中可以看出,我正在尝试选择 academy.division_id = 19 的团队。

然而这不起作用

我还尝试了以下方法:
Team.findAll({include: [{all: true}], where: {division_id: 19 }}, {})
.ok(onSuccess).error(onError);

可悲的是,这产生了以下 sql:
where academy_team.division_id = 19

最佳答案

如果需要 where 条件,则不能使用 include all

Team.findAll({
include: [
{ model: academy, where: { division_id: 19 }
]
});

关于javascript - Sequelize ,其中relation.attribute 等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29624277/

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