Mysql 是否可以在Sequelize关系中添加额外字段?
我有如下关系:Mysql 是否可以在Sequelize关系中添加额外字段?,mysql,sequelize.js,Mysql,Sequelize.js,我有如下关系: classMethods: { associate: function(models) { User.belongsTo(models.Prefs, {timestamps: false, foreignKey: 'Type', targetKey: 'UserType'}) } } 产生 LEFT OUTER JOIN `prefs` AS `Prefs` ON `User`.`Type` = `Prefs`.`UserType` 问题是
classMethods: {
associate: function(models) {
User.belongsTo(models.Prefs, {timestamps: false, foreignKey: 'Type', targetKey: 'UserType'})
}
}
产生
LEFT OUTER JOIN `prefs` AS `Prefs` ON `User`.`Type` = `Prefs`.`UserType`
问题是,我还需要添加额外的检查,如
AND `Prefs`.`Section` = 'GLOBAL'
有可能吗?我相信这是重复的 您需要在JOIN子句中使用customon条件 编辑 我相信这就是你要找的。尝试将其添加到关联中
classMethods: {
associate: function(models) {
User.belongsTo(
models.Prefs,
{
timestamps: false,
foreignKey: 'Type',
targetKey: 'UserType',
scope: { Section: 'GLOBAL' }
}
);
}
}
我需要在model classI更新的答案中指定此项,我希望此项将帮助您。
classMethods: {
associate: function(models) {
User.belongsTo(
models.Prefs,
{
timestamps: false,
foreignKey: 'Type',
targetKey: 'UserType',
scope: { Section: 'GLOBAL' }
}
);
}
}