TypeORM一对一关系,其中特定值匹配

时间:2019-06-06 21:53:16

标签: typescript typeorm

我有两个实体,促销:

@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,我该怎么办?

0 个答案:

没有答案