import { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm'; import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { ProductEntity } from '../../product/entities/product.entity'; import { SpaceProductAllocationEntity } from '../../space/entities/space-product-allocation.entity'; import { NewTagEntity } from '../../tag/entities/tag.entity'; import { SpaceModelEntity } from './space-model.entity'; @Entity({ name: 'space_model_product_allocation' }) @Unique(['spaceModel', 'product', 'tag']) export class SpaceModelProductAllocationEntity extends AbstractEntity { @Column({ type: 'uuid', default: () => 'gen_random_uuid()', nullable: false, }) public uuid: string; @ManyToOne( () => SpaceModelEntity, (spaceModel) => spaceModel.productAllocations, { nullable: false, onDelete: 'CASCADE' }, ) public spaceModel: SpaceModelEntity; @ManyToOne(() => ProductEntity, { nullable: false, onDelete: 'CASCADE' }) public product: ProductEntity; @ManyToOne(() => NewTagEntity, { nullable: true, onDelete: 'CASCADE' }) public tag: NewTagEntity; @OneToMany( () => SpaceProductAllocationEntity, (allocation) => allocation.inheritedFromModel, { cascade: true, }, ) public inheritedSpaceAllocations: SpaceProductAllocationEntity[]; constructor(partial: Partial) { super(); Object.assign(this, partial); } }