feat: add join columns
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
BaseEntity,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Message } from './message.entity';
|
||||
|
||||
@@ -19,7 +20,15 @@ export class Conversation extends BaseEntity {
|
||||
@Column({ type: 'varchar', nullable: true })
|
||||
title!: string | null;
|
||||
|
||||
@Column({
|
||||
type: 'int',
|
||||
name: 'userId',
|
||||
nullable: false,
|
||||
})
|
||||
userId!: number;
|
||||
|
||||
@ManyToOne(() => User, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'userId' })
|
||||
user!: User;
|
||||
|
||||
@OneToMany(() => Message, (message) => message.conversation)
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
BaseEntity,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Conversation } from './conversation.entity';
|
||||
import { MessageRole } from '../enums/message-role.enum';
|
||||
@@ -14,9 +15,17 @@ export class Message extends BaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: number;
|
||||
|
||||
@Column({
|
||||
type: 'int',
|
||||
name: 'conversationId',
|
||||
nullable: false,
|
||||
})
|
||||
conversationId!: number;
|
||||
|
||||
@ManyToOne(() => Conversation, (conversation) => conversation.messages, {
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'conversationId' })
|
||||
conversation!: Conversation;
|
||||
|
||||
@Column({
|
||||
|
||||
Reference in New Issue
Block a user