import { Column, Entity, ManyToOne, JoinColumn } from 'typeorm'; import { SpaceEntity } from './space.entity'; import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { ProductEntity } from '../../product/entities'; @Entity({ name: 'space-product' }) export class SpaceProductEntity extends AbstractEntity { @ManyToOne(() => SpaceEntity, (space) => space.spaceProducts, { nullable: false, onDelete: 'CASCADE', }) @JoinColumn({ name: 'space_id' }) space: SpaceEntity; @ManyToOne(() => ProductEntity, (product) => product.spaceProducts, { nullable: false, onDelete: 'CASCADE', }) @JoinColumn({ name: 'product_id' }) product: ProductEntity; @Column({ nullable: false, type: 'int', }) productCount: number; constructor(partial: Partial) { super(); Object.assign(this, partial); } }