0

「具体化されたパス」ツリー構造を持つエンティティがあります。

私は子供たちをロードしようとしています。これは空の子オブジェクトを与えます以下はエンティティです

 @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;
}

ツリー要素を取得するためのコード

return typeorm.getTreeRepository(SectorEntity).findTrees();

子オブジェクト内にデータがない場合、ロード後に得られる結果

[
    {
        "id": 1,
        "name": "Abc",
        "createdAt": "2021-04-29T18:50:19.922Z",
        "updatedAt": "2021-04-29T18:50:19.000Z",        
        "children": []
    }
]

どこが間違っているのか教えてください。

4

1 に答える 1