fix(server): 档案子记录编辑修复 ER_BAD_FIELD_ERROR
findOne+select+eager join 时 TypeORM 0.3.x 生成缺 id 列的 distinctAlias 子查询 (Unknown column 'distinctAlias.xxx_id'),所有档案子记录编辑/删除均 500。 改回全列读取(单行主键查询成本可忽略)
This commit is contained in:
@@ -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<number | null> {
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user