Nestjs 如何使用带有typeorm的物化路径树结构加载树
我有一个具有“物化路径”树结构的实体 我正在给孩子们装东西。它给出了一个空的子对象 以下是实体Nestjs 如何使用带有typeorm的物化路径树结构加载树,nestjs,typeorm,materialized-path-pattern,Nestjs,Typeorm,Materialized Path Pattern,我有一个具有“物化路径”树结构的实体 我正在给孩子们装东西。它给出了一个空的子对象 以下是实体 @Entity({ name: 'sector' }) @Tree('materialized-path') export class SectorEntity { constructor(data?: Partial<SectorEntity>) { Object.assign(this, data); } @ApiProperty(
@Entity({ name: 'sector' })
@Tree('materialized-path')
export class SectorEntity {
constructor(data?: Partial<SectorEntity>) {
Object.assign(this, data);
}
@ApiProperty({ type: 'string' })
@PrimaryGeneratedColumn()
id: number;
@ApiProperty()
@Column()
name: string;
@ApiProperty()
@CreateDateColumn({ type: 'timestamp' })
createdAt?: Date;
@ApiProperty()
@UpdateDateColumn({ type: 'timestamp' })
updatedAt?: Date;
@TreeChildren()
children: SectorEntity[];
@TreeParent()
parent: SectorEntity;
}
加载后得到的结果,其中子对象中没有数据
[
{
"id": 1,
"name": "Abc",
"createdAt": "2021-04-29T18:50:19.922Z",
"updatedAt": "2021-04-29T18:50:19.000Z",
"children": []
}
]
请告诉我哪里出了问题。希望你的问题已经解决了。我也遇到过类似的问题,我的错误是在保存新记录时,我只在
parent
列中保存了父Id,但如果我们查看我们的实体,我们有:parent:sectoreentity代码>所以用实际的父实体更新我端的create函数对我来说很有效
[
{
"id": 1,
"name": "Abc",
"createdAt": "2021-04-29T18:50:19.922Z",
"updatedAt": "2021-04-29T18:50:19.000Z",
"children": []
}
]