How to select all tree nodes of model hierarchy? children
is association of model itself.
@Table
export class Department extends ADEntity {
@ForeignKey(() => Department)
@Column({
type: DataType.INTEGER,
allowNull: true,
})
parentId: number;
@BelongsTo(() => Department)
parent: Department;
@Column({
type: DataType.STRING,
allowNull: false,
})
ou: string;
@HasMany(() => Department)
children: Department[];
public static associations: {
parent: Association<Department, Department>;
children: Association<Department, Department>;
};
}