从TypeORM的文档中,他们通过以下示例描述了具体表继承:
export abstract class Content {
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
@Column()
description: string;
}
@Entity()
export class Photo extends Content {
@Column()
size: string;
}
@Entity()
export class Question extends Content {
@Column()
answersCount: number;
}
@Entity()
export class Post extends Content {
@Column()
viewCount: number;
}
我的问题是,是否要向抽象类添加关系。所以....
export abstract class Content {
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
@Column()
description: string;
// WOULD LIKE TO ADD SOMETHING LIKE THIS ...
@ManyToOne(() => User, user => user.createdContent)
createdBy: User
}
@Entity()
export default class User {
// AND THIS ...
@OneToMany(() => Content, content => content.authoredBy)
authoredContent: Content[]
}
有没有可能的解决方案使之成为可能。注意:您可以使用“单表继承”来实现