import { Column, Entity, ManyToOne, JoinColumn, OneToMany } from 'typeorm'; import { SpaceEntity } from './space.entity'; import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { ProductEntity } from '../../product/entities'; import { SpaceProductItemEntity } from './space-product-item.entity'; import { SpaceProductModelEntity } from '../../space-model'; @Entity({ name: 'space-product' }) export class SpaceProductEntity extends AbstractEntity { @ManyToOne(() => SpaceEntity, (space) => space.spaceProducts, { nullable: false, onDelete: 'CASCADE', }) @JoinColumn({ name: 'space_uuid' }) space: SpaceEntity; @ManyToOne(() => ProductEntity, (product) => product.spaceProducts, { nullable: false, onDelete: 'CASCADE', }) @JoinColumn({ name: 'product_uuid' }) product: ProductEntity; @Column({ nullable: false, type: 'int', }) productCount: number; @OneToMany(() => SpaceProductItemEntity, (item) => item.spaceProduct, { cascade: true, }) public items: SpaceProductItemEntity[]; @ManyToOne( () => SpaceProductModelEntity, (spaceProductModel) => spaceProductModel.spaceProducts, { nullable: true, }, ) @JoinColumn({ name: 'space_product_model_uuid' }) public spaceProductModel?: SpaceProductModelEntity; constructor(partial: Partial) { super(); Object.assign(this, partial); } }