diff --git a/apps/server/src/archive/archive.service.ts b/apps/server/src/archive/archive.service.ts index bca07007..92cae657 100644 --- a/apps/server/src/archive/archive.service.ts +++ b/apps/server/src/archive/archive.service.ts @@ -65,6 +65,9 @@ export class ArchiveService { /** * 解析某条档案子记录属于哪个学生(用于按学生范围做 IDOR 校验)。 * 找不到返回 null。 + * 注意:不传 select —— 这些实体带 eager 的 student 关系,TypeORM 0.3.x 对 + * findOne+select+eager join 会生成缺 id 列的 distinctAlias 子查询而报 + * ER_BAD_FIELD_ERROR(单行主键查询,全列读取成本可忽略)。 */ async resolveRecordStudentId( kind: 'enrollment' | 'examScore' | 'learningRecord' | 'attachment', @@ -72,19 +75,19 @@ export class ArchiveService { ): Promise { switch (kind) { case 'enrollment': { - const row = await this.enrollmentRepo.findOne({ where: { id }, select: ['studentId'] }); + const row = await this.enrollmentRepo.findOne({ where: { id } }); return row?.studentId ?? null; } case 'examScore': { - const row = await this.examScoreRepo.findOne({ where: { id }, select: ['studentId'] }); + const row = await this.examScoreRepo.findOne({ where: { id } }); return row?.studentId ?? null; } case 'learningRecord': { - const row = await this.learningRecordRepo.findOne({ where: { id }, select: ['studentId'] }); + const row = await this.learningRecordRepo.findOne({ where: { id } }); return row?.studentId ?? null; } case 'attachment': { - const row = await this.attachmentRepo.findOne({ where: { id }, select: ['studentId'] }); + const row = await this.attachmentRepo.findOne({ where: { id } }); return row?.studentId ?? null; } default: