Typescript 类型化FindDescents会产生意外的结果(它会自行返回)
考虑以下几点:Typescript 类型化FindDescents会产生意外的结果(它会自行返回),typescript,typeorm,Typescript,Typeorm,考虑以下几点: @Entity() @Tree('closure-table') export class Group { @PrimaryGeneratedColumn('uuid') id: string; @Column() name: string; @TreeChildren() children: Group[]; @TreeParent() parent: Group; } 然后让我们创建一些组 const groupRepo = con
@Entity()
@Tree('closure-table')
export class Group {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
name: string;
@TreeChildren()
children: Group[];
@TreeParent()
parent: Group;
}
然后让我们创建一些组
const groupRepo = conn.getRepository(Group)
const parentGroup = new Group()
parentGroup.name = "dogs"
await groupRepo.save(parentGroup)
const childGroup = new Group()
childGroup.name = "puppies";
childGroup.parent = parentGroup;
await groupRepo.save(childGroup)
好的,现在尝试加载树:
const groupTreeRepo = conn.getTreeRepository(Group);
const parent = await groupRepo.findOne(group.id);
const trees = await groupTreeRepo.findTrees();
// yields the expected result
// a single tree `dogs` with `puppies` as child
console.log('Trees', trees);
const children = await groupTreeRepo.findDescendants(parent);
// yields unexpected results: yields both groups.
// i only expect this to return the puppy group
console.log('Children: ', children);
我是否有(a)配置错误或(b)调用findDesendants
的方式错误