Отношение TypeORM: как получить Entites из отношений с пользовательскими свойствами Таблица - PullRequest
0 голосов
/ 24 февраля 2020

У меня есть отношения многие ко многим с пользовательскими свойствами. от https://github.com/typeorm/typeorm/blob/master/docs/many-to-many-relations.md Теперь мне нравится получать связанные сущности.

Как объединить таблицу или столбец таблицы отношений?

@Entity({name: 'a'})
export class A {
  @PrimaryGeneratedColumn()
  id: number;

  @OneToMany(type => AB, ab => ab.a, )
  abs: ab[];

  ??? // how to get array of B here?
  b: B[];
}

@Entity({name: 'b'})
export class B {
  @PrimaryGeneratedColumn()
  id: number;

  @OneToMany(type => AB, ab => ab.b, )
  abs: ab[];
}

@Entity()
export class AB {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    public aId!: number;

    @Column()
    public bId!: number;

    @Column()
    public position!: number;

    @ManyToOne(type => A, a => a.abs,)
    public a!: A;

    @ManyToOne(type => B,b => b.abs)
    public b!: B;
}

База данных

| A | B  | AB 
----------------------------------
|id | id | id, aId, bId. position

ответ должен быть

a = {
    id: 1,
    abs: [
        {
            "id": 1,
            "aId": 1,
            "bId": 1,
            "position": 1
        }
    ],
    b:[{"id: 1"}] // need this
}
...