最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - How to use TypeORM with generic types? - Stack Overflow

programmeradmin7浏览0评论

I create a Nest project with many generic entities. I have two abstract classes :

@Entity()
export abstract class GenericEntity {
  @PrimaryGeneratedColumn('uuid')
  id: string;


  @Column()
  name: string;

  @OneToMany(() => AdditionalField, field => field.entity, {
    eager: true,
    cascade: true
  })
  additionalFields: AdditionalField[];
} 



@Entity()
export abstract class AdditionalField {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  name: string;

  @ManyToOne(() => GenericEntity, entity => entity.additionalFields)
  @JoinColumn()
  entity: GenericEntity;
} 

The problem is that implementation does not work. If I extends my classes, the child classes have foreign keys of generic entities and that cause 500 error at execution. What is the best way to do that? (I have many different type of additionalFields, and many different type of generic Entities).

发布评论

评论列表(0)

  1. 暂无评论