Added space product relation

This commit is contained in:
hannathkadher
2024-11-20 16:16:17 +04:00
parent dcbc74807d
commit 2ed5d9dce7
5 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,32 @@
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<SpaceProductEntity> {
@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<SpaceProductEntity>) {
super();
Object.assign(this, partial);
}
}