gpt4 book ai didi

node.js - Sequelize : Only returning one of many result for a nested include

转载 作者:太空宇宙 更新时间:2023-11-04 02:45:14 24 4
gpt4 key购买 nike

我有 3 个表:

  1. 职位发布
  2. 招聘阶段
  3. 采访时段

他们的关联是,职位发布有许多招聘阶段,并且招聘阶段有很多面试机会

我可以通过包含招聘阶段关联和组条款来获取职位的所有招聘阶段。

const jobPosts = await JobPost.unscoped().findAll({
where,
include: [
{
model: db.RecruitmentPhase,
include: [{
model: db.InterviewSlot,
},

],
group: ['RecruitmentPhases.id'],
});

但我在招聘阶段只获得了一个面试机会,尽管该招聘阶段有许多面试机会。

我尝试在包含内执行组子句。

const jobPosts = await JobPost.unscoped().findAll({
where,
include: [
{
model: db.RecruitmentPhase,
group: ['InterviewSlots.id'],
include: [{
model: db.InterviewSlot,
},

],
group: ['RecruitmentPhases.id'],
});

但它也只提供一个面试机会

编辑

职位模型:

module.exports = (sequelize, DataTypes) => {
const jobPost = sequelize.define('JobPost', {
id: {
type: DataTypes.BIGINT,
allowNull: true,
autoIncrement: true,
primaryKey: true,
},
jobTitle: {
type: DataTypes.STRING(150),
allowNull: true,
},

}, {
timestamps: true,
defaultScope: {
attributes: { exclude: ['createdAt', 'updatedAt'] },
},
});
jobPost.associate = (models) => {
jobPost.hasMany(models.RecruitmentPhase);
};
return jobPost;
};

招聘阶段模型:

module.exports = (sequelize, DataTypes) => {
const recruitmentPhase = sequelize.define('RecruitmentPhase', {
id: {
type: DataTypes.BIGINT,
allowNull: true,
autoIncrement: true,
primaryKey: true,
},

phaseName: {
type: DataTypes.STRING(200),
allowNull: true,
},

}, {
timestamps: true,
});
recruitmentPhase.associate = (models) => {
recruitmentPhase.belongsTo(models.JobPost);
recruitmentPhase.hasMany(models.InterviewSlot);
};
return recruitmentPhase;
};

采访时段模型:

module.exports = (sequelize, DataTypes) => {
const interviewSlot = sequelize.define('InterviewSlot', {
id: {
type: DataTypes.BIGINT,
allowNull: true,
autoIncrement: true,
primaryKey: true,
},
interviewDate: {
type: DataTypes.DATE,
allowNull: true,
},
});
interviewSlot.associate = (models) => {
interviewSlot.belongsTo(models.RecruitmentPhase);
};
return interviewSlot;
};

最佳答案

删除组:['Recruitment Phases.of'],以查看面试时段的详细信息。就好像您正在看到面试时段的摘要一样......

关于node.js - Sequelize : Only returning one of many result for a nested include,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55955192/

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