added project space model relation

This commit is contained in:
hannathkadher
2024-12-10 17:33:50 +04:00
parent 3ee3ff1fc3
commit dc00fdc554
2 changed files with 22 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import { Entity, Column, Unique, OneToMany } from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { ProjectDto } from '../dtos'; import { ProjectDto } from '../dtos';
import { CommunityEntity } from '../../community/entities'; import { CommunityEntity } from '../../community/entities';
import { SpaceModelEntity } from '../../space-model';
@Entity({ name: 'project' }) @Entity({ name: 'project' })
@Unique(['name']) @Unique(['name'])
@ -20,7 +21,10 @@ export class ProjectEntity extends AbstractEntity<ProjectDto> {
@Column({ length: 255, nullable: true }) @Column({ length: 255, nullable: true })
description: string; description: string;
@OneToMany(() => SpaceModelEntity, (spaceModel) => spaceModel.project)
public spaceModels: SpaceModelEntity[];
@OneToMany(() => CommunityEntity, (community) => community.project) @OneToMany(() => CommunityEntity, (community) => community.project)
communities: CommunityEntity[]; communities: CommunityEntity[];

View File

@ -1,10 +1,19 @@
import { Entity, Column, OneToMany } from 'typeorm'; import {
Entity,
Column,
OneToMany,
ManyToOne,
JoinColumn,
Unique,
} from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { SpaceModelDto } from '../dtos'; import { SpaceModelDto } from '../dtos';
import { SubspaceModelEntity } from './subspace-model.entity'; import { SubspaceModelEntity } from './subspace-model.entity';
import { SpaceProductModelEntity } from './space-product-model.entity'; import { SpaceProductModelEntity } from './space-product-model.entity';
import { ProjectEntity } from '../../project/entities';
@Entity({ name: 'space-model' }) @Entity({ name: 'space-model' })
@Unique(['modelName', 'project'])
export class SpaceModelEntity extends AbstractEntity<SpaceModelDto> { export class SpaceModelEntity extends AbstractEntity<SpaceModelDto> {
@Column({ @Column({
type: 'uuid', type: 'uuid',
@ -18,6 +27,13 @@ export class SpaceModelEntity extends AbstractEntity<SpaceModelDto> {
}) })
public modelName: string; public modelName: string;
@ManyToOne(() => ProjectEntity, (project) => project.spaceModels, {
nullable: false,
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'project_uuid' })
public project: ProjectEntity;
@OneToMany( @OneToMany(
() => SubspaceModelEntity, () => SubspaceModelEntity,
(subspaceModel) => subspaceModel.spaceModel, (subspaceModel) => subspaceModel.spaceModel,