我有两个实体,促销:
@Entity()
export class Promotion extends BaseEntity {
@PrimaryColumn()
public id: number;
@Column()
public title: string;
@Column()
public ean: string;
@Column()
public discountPrice: string;
@Column()
public validUntil: Date;
}
和产品:
@Entity()
export class Product extends BaseEntity {
@PrimaryColumn()
public id: number;
@Column()
public ean: string;
@Column()
public title: string;
@Column()
public brand: string;
@Column({ nullable: true })
public shortdescription: string;
@Column({ nullable: true })
public fulldescription: string;
@Column()
public image: string;
@Column()
public weight: string;
@Column()
public price: string;
@Column()
public category: string;
@Column()
public subcategory: string;
@Column()
public subsubcategory: string;
@OneToOne((_) => Promotion, (promotion) => promotion.ean)
@JoinColumn()
public promotion: Promotion;
}
我将数据保存在单独的文件中,因为我是从api中获取数据的,现在我想让TypeORM在产品表中设置外键PromotionId
以匹配ean匹配的行的ID,我该怎么办?