TypeORM关系:如何从具有自定义属性表的关系中获取实体

时间:2020-02-24 15:29:15

标签: mysql node.js nestjs typeorm

我与自定义属性有多对多关系。来自https://github.com/typeorm/typeorm/blob/master/docs/many-to-many-relations.md 现在,我想获取相关的实体。

如何联接表或关系表的列?

from channels.db import database_sync_to_async
import time
import pymongo
conn = pymongo.MongoClient('xxxx', 27017)

db = conn['test']

async def  insert():
    time.sleep(1)
    print(1111111)
    resul =await db.test_collection.insert_many([{'key': "key{}".format(i)} for i in range(10)])



class Index(View):
    def get(self, request):
        print(2222222)
        loop = asyncio.get_event_loop()
        loop.run_until_complete(insert)
        print(333333333)
        return JsonResponse({'1': 111})

数据库

    raise NotImplementedError
NotImplementedError

响应应该是

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

0 个答案:

没有答案