Здравствуйте. Я пишу серверную часть приложения с помощью TypeOrm. Мне необходимо объединить две таблицы, но без вложенности.
import {Column, Entity, OneToMany, PrimaryColumn} from "typeorm";
import {Oper_equipment} from "./oper_equipment";
import {Number_equipment} from "./Number_equipment";
@Entity()
export class Equipment {
@PrimaryColumn({length: 50})
equipment_id:string
@Column({length: 50})
name_equipment:string
@OneToMany(() => Oper_equipment, oper_equipment => oper_equipment.equipment)
oper_equipment: Oper_equipment[]
@OneToMany(() => Number_equipment, number_equipment => number_equipment.equipment)
number_equipment: Number_equipment[]
}
import {Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryColumn} from "typeorm";
import {Equipment} from "./Equipment";
import {Oper_equipment} from "./oper_equipment";
@Entity()
export class Number_equipment {
@PrimaryColumn({length: 50})
number_id:string
@Column()
inventory_number:number
@Column()
code_equipment:number
@Column({length: 50})
equipment_id:string
@ManyToOne(
() => Equipment,
equipment => equipment.number_equipment,
{onDelete: "CASCADE"}
)
@JoinColumn({name: "equipment_id"})
equipment: Equipment
@OneToMany(() => Oper_equipment, oper_equipment => oper_equipment.number_equipment)
oper_equipment: Oper_equipment[]
}
Объединение:
oper["equipment"] = await repository_equipment
.createQueryBuilder("eq")
.select(["eq.equipment_id", "eq.name_equipment", "n_e.inventory_number", "n_e.code_equipment"])
.leftJoin("eq.number_equipment", "n_e")
.where("eq.equipment_id = :equipment_id", {equipment_id})
.andWhere("n_e.number_id = :number_id", {number_id})
.getMany()
После выполнения этого кода возникает вложенность:
Мне нужно, чтобы получалось без вложенности:
Я пробовал джойнить сущность:
oper["equipment"] = await repository_equipment
.createQueryBuilder("eq")
.select(["eq.equipment_id", "eq.name_equipment", "n_e.inventory_number", "n_e.code_equipment"])
.leftJoin(Number_equipment, "n_e", "n_e.equipment_id = eq.equipment_id")
.where("eq.equipment_id = :equipment_id", {equipment_id})
.andWhere("n_e.number_id = :number_id", {number_id})
.getMany()
В итоге выводятся только столбцы сущности equipment.
Подскажите, как можно это сделать?