我有两个实体:
@Entity('cast')
export class Cat {
@PrimaryGeneratedColumn()
cat_id: number;
@JoinColumn({ name: 'owner_id' })
@ManyToOne(() => Owner, (owner) => owner.owner_id)
owner_id: Owner;
}
@Entity('owners')
export class Owner {
@PrimaryColumn('uuid')
owner_id: string;
@Column()
description: string;
@Column()
datetime: Date;
}
如何正确添加 OneToMany 装饰器,这样我就可以获得这样的结果 (具有 owner_id = owner.owner_id 的 Cat 实体的列表):
const response = await ownerRepo.find(...);
response //
[{
owner_id: 'aaa',
description: 'hello',
datetime: 'iso string',
cats: [
{
cat_id: 1,
owner_id: 'aaa',
},
{
cat_id: 2,
owner_id: 'aaa',
},
]
}]
我需要一组具有匹配owner_id的猫。