added project community relation

This commit is contained in:
hannathkadher
2024-12-09 15:41:45 +04:00
parent a74e6dfac6
commit ab8466bf32
2 changed files with 12 additions and 2 deletions

View File

@ -1,7 +1,8 @@
import { Column, Entity, OneToMany, Unique } from 'typeorm';
import { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { CommunityDto } from '../dtos';
import { SpaceEntity } from '../../space/entities';
import { ProjectEntity } from '../../project/entities';
@Entity({ name: 'community' })
@Unique(['name'])
@ -31,4 +32,9 @@ export class CommunityEntity extends AbstractEntity<CommunityDto> {
nullable: true,
})
externalId: string;
@ManyToOne(() => ProjectEntity, (project) => project.communities, {
nullable: false,
})
project: ProjectEntity;
}

View File

@ -1,6 +1,7 @@
import { Entity, Column, Unique } from 'typeorm';
import { Entity, Column, Unique, OneToMany } from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { ProjectDto } from '../dtos';
import { CommunityEntity } from '../../community/entities';
@Entity({ name: 'project' })
@Unique(['name'])
@ -19,6 +20,9 @@ export class ProjectEntity extends AbstractEntity<ProjectDto> {
@Column({ length: 255, nullable: true })
description: string;
@OneToMany(() => CommunityEntity, (community) => community.project)
communities: CommunityEntity[];
constructor(partial: Partial<ProjectEntity>) {
super();