TypeORM findDescendants产生意外结果(返回自身)

时间:2019-03-08 20:28:14

标签: typescript typeorm

请考虑以下内容:

@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的地方

0 个答案:

没有答案