fix: questionOption composite FK
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
import { Entity, PrimaryGeneratedColumn, ManyToOne, Unique } from 'typeorm';
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
ManyToOne,
|
||||
Unique,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Question } from './question.entity';
|
||||
import { User } from './user.entity';
|
||||
import { QuestionOption } from './questionOptions';
|
||||
|
||||
@Entity()
|
||||
@Unique(['question', 'choice', 'user'])
|
||||
@Unique(['questionOption', 'user'])
|
||||
export class Answer {
|
||||
@PrimaryGeneratedColumn({})
|
||||
id: number;
|
||||
|
||||
@ManyToOne(() => QuestionOption)
|
||||
choice: QuestionOption;
|
||||
@JoinColumn([
|
||||
{ name: 'questionId', referencedColumnName: 'question' },
|
||||
{ name: 'choiceId', referencedColumnName: 'choice' },
|
||||
])
|
||||
questionOption: QuestionOption;
|
||||
|
||||
@ManyToOne(() => Question, (question: Question) => question.answers)
|
||||
@JoinColumn([{ name: 'questionId', referencedColumnName: 'id' }])
|
||||
question: Question;
|
||||
|
||||
@ManyToOne(() => User)
|
||||
|
||||
Reference in New Issue
Block a user