我在 Node.JS 中使用 TypeORM,并希望使用实体继承来实现 BaseRecord:
export abstract class BaseRecord {
@CreateDateColumn({type: 'timestamp'})
public created_at: Date;
@UpdateDateColumn({type: 'timestamp'})
public updated_at: Date;
@ManyToOne(type => User, user => user.records_created)
public created_by: User
@ManyToOne(type => User, user => user.records_updated)
public updated_by: User
}
我想通过它来扩展其他实体。这在删除 @ManyToOne 关系时按预期工作:
@Entity()
export class Address extends BaseRecord {
@PrimaryGeneratedColumn()
public id: number;
@Column({ nullable: true, type: "text" })
public alias: string;
@Column({ type: "text" })
public street_1: string;
@Column({ nullable: true, type: "text" })
public street_2: string;
@Column({ type: "text" })
public city: string;
@Column({ type: "text" })
public state: string;
@Column({ type: "text" })
public zip_code: string;
@Column(type => GeoLocation)
public geo_location: GeoLocation
}
有没有人遇到过这个或继承实体并具有多对一关系的方法?