ensure in uniqueness in tag

This commit is contained in:
hannathkadher
2024-12-11 10:37:21 +04:00
parent dc00fdc554
commit b945740fb8

View File

@ -1,10 +1,11 @@
import { Entity, Column, ManyToOne } from 'typeorm';
import { Entity, Column, ManyToOne, Unique } from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { SpaceEntity } from '../../space/entities';
import { SpaceProductItemDto } from '../dtos';
import { SpaceProductModelEntity } from './space-product-model.entity';
import { SpaceModelEntity } from './space-model.entity';
@Entity({ name: 'space-product-item' })
@Unique(['tag', 'spaceProductModel', 'spaceModel'])
export class SpaceProductItemModelEntity extends AbstractEntity<SpaceProductItemDto> {
@Column({
nullable: false,
@ -16,14 +17,16 @@ export class SpaceProductItemModelEntity extends AbstractEntity<SpaceProductItem
(spaceProductModel) => spaceProductModel.items,
{
nullable: false,
onDelete: 'CASCADE',
},
)
public spaceProductModel: SpaceProductModelEntity;
@ManyToOne(() => SpaceEntity, (space) => space.spaceProducts, {
nullable: true,
onDelete: 'CASCADE',
})
public space: SpaceEntity; // Optional for associating the item to a space directly
@ManyToOne(
() => SpaceModelEntity,
(spaceModel) => spaceModel.spaceProductModels,
{
nullable: false,
},
)
public spaceModel: SpaceModelEntity;
}