我有这堂课:
import {Column, Entity, ManyToOne, PrimaryGeneratedColumn} from "typeorm";
import {Company} from "./company.entity";
import {classToPlain, Expose, Transform, Type} from 'class-transformer';
@Entity()
export class Space {
@PrimaryGeneratedColumn('uuid')
id?: string;
@ManyToOne(() => Company)
@Expose()
@Type(() => Company)
@Transform(async value => {
const res = await value;
console.log(res);
return res;
})
company!: Promise<Company>;
@Column()
name!: string;
}
这对于Company
:
@Entity()
export class Company {
@PrimaryGeneratedColumn('uuid')
id?: string;
@Column()
name!: string;
@OneToMany(() => Space, space => space.company, {
cascade: true
})
spaces!: Promise<Space[]>;
}
出于某种原因,Company
总是作为空间对象中的空对象返回,如下所示:
[
{
"id": "266F2B95-69AE-EA11-96D2-28187800655A",
"name": "Main",
"desks": 2,
"company": {}
}
]
即使 console.log 吐出
Company {
id: '09A8FB3E-C5AB-EA11-96D2-28187800655A',
name: 'Name' }
我在这里做错了什么?