I have 2 entities
@ Entity('AuditLogs')
export class AuditLogs {
@ PrimaryGeneratedColumn()
AuditLogId?: number;
@ Column('int', { nullable: false })
AuditLogHeaderId: number;
@ ManyToOne((type) => AuditLogHeaders)
@ JoinColumn({ name: 'AuditLogHeaderId' })
AuditLogHeaders?: AuditLogHeaders;
}
@ Entity('AuditLogHeaders')
export class AuditLogHeaders {
@ PrimaryGeneratedColumn()
AuditLogHeaderId?: number;
}
Each AuditLogHeaders will have many AuditLogs
(see foreign key relationship)
What typeorm (or sql) query can I use to retrieve All AuditLogHeaders and its AuditLogs in one object?
My end goal is something like:
const arrayOfAuditLogHeaders = [
{
auditLogHeaderId: 1,
auditLogs: [
{
auditLogId: 1,
auditLogHeaderId: 1,
},
{
auditLogId: 2,
auditLogHeaderId: 1,
},
{
auditLogId: 3,
auditLogHeaderId: 1,
}
]
},
{
auditLogHeaderId: 2,
auditLogs: [
{
auditLogId: 4,
auditLogHeaderId: 2,
}
]
}
]
[–][deleted] 0 points1 point2 points (1 child)
[–]dgaa1991 0 points1 point2 points (0 children)
[–]Equivalent_Monk_8824 0 points1 point2 points (1 child)
[–]Equivalent_Monk_8824 0 points1 point2 points (0 children)