Cascading entities

This commit is contained in:
2023-11-20 21:51:29 +03:00
parent fcf15d668f
commit 9ead1095a9
2 changed files with 2 additions and 4 deletions

View File

@@ -13,7 +13,7 @@ export class Admin {
@Column({ nullable: false })
public user_id!: string;
@OneToOne(() => User, (user) => user.id)
@OneToOne(() => User, (user) => user.id, { onDelete: 'CASCADE', onUpdate: 'CASCADE' })
@JoinColumn({ name: 'user_id' })
public user!: User;
}

View File

@@ -1,4 +1,3 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm';
import { Post } from './post.entity';
@@ -20,8 +19,7 @@ export class Image {
@Column({ nullable: false })
public post_uuid!: string;
@ApiProperty({})
@ManyToOne(() => Post, (post) => post.uuid)
@ManyToOne(() => Post, (post) => post.uuid, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'post_uuid' })
public post!: Post;
}