sequelize客户hasMany关系返回1行而不是多行。 对于该问题,我已经删除了模型中钩子的代码。
父母餐桌弹药
module.exports = function (app) {
const sequelizeClient = app.get('sequelizeClient');
const munitions = sequelizeClient.define('munitions', {
//Comments //Comments
id: {
type: DataTypes.BIGINT,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
name: Sequelize.TEXT,
thickness: Sequelize.DOUBLE,
});
munitions.associate = function (models) {
munitions.hasMany(models.munition_fuses, {
foreignKey: 'munition_id',
sourceKey: 'id',
});
};
return munitions;
};
子表弹药保险丝
module.exports = function (app) {
const sequelizeClient = app.get('sequelizeClient');
const munitionfuses = sequelizeClient.define('munition_fuses', {
//Comments
id: {
type: DataTypes.BIGINT,
primaryKey: true,
autoIncrement: true
},
munition_id: Sequelize.BIGINT,
fuse_type_id: Sequelize.SMALLINT,
description: Sequelize.STRING,
});
munitionfuses.associate = function (models) {
munitionfuses.belongsTo(models.munitions, {
foreignKey: 'munition_id',
targetKey: 'id'
});
};
return munitionfuses; //
};//
弹药钩
context.params.sequelize = {
include:
[
{
model: munitionFuses
}
};
sequelize Client hasMany关系返回1行而不是多个