您好,我有 1:n 关系,在寻找关系时,我想建立关系:
像这样:
{
id: '7e413f8d-2a07-4f2e-bbc9-eb8892948a03',
departament_name: 'test',
employee: {
employee_id: 'a9c678bb-c274-4908-add0-34a856d2458e',
matricula: '123',
departament_id: '7e413f8d-2a07-4f2e-bbc9-eb8892948a03',
first_name: 'test',
last_name: 'test2'
}
}
但我得到了这个:
{
id: '7e413f8d-2a07-4f2e-bbc9-eb8892948a03',
departament_name: 'test',
manager_id: 'a9c678bb-c274-4908-add0-34a856d2458e',
employee_id: 'a9c678bb-c274-4908-add0-34a856d2458e',
matricula: '123',
departament_id: '7e413f8d-2a07-4f2e-bbc9-eb8892948a03',
first_name: 'test',
last_name: 'test2'
}
询问:
const rawDepartament = await this.db
.select([
`${this.tableName}.id`,
`${this.tableName}.departament_name`,
`${this.tableName}.manager_id`,
`employees.id as employee_id`,
`employees.matricula`,
`employees.departament_id`,
`employees.first_name`,
`employees.last_name`,
])
.from<Departament>(this.tableName)
.where({ departament_name })
.innerJoin<Employee>(
'employees',
`${this.tableName}.manager_id`,
'employees.id',
)
.first();
console.log(rawDepartament);
关系:
有人可以帮助我如何将我的查询结果格式化为 typeorm 返回之类的东西吗?