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 { Question } from './question.entity';
|
||||||
import { User } from './user.entity';
|
import { User } from './user.entity';
|
||||||
import { QuestionOption } from './questionOptions';
|
import { QuestionOption } from './questionOptions';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
@Unique(['question', 'choice', 'user'])
|
@Unique(['questionOption', 'user'])
|
||||||
export class Answer {
|
export class Answer {
|
||||||
@PrimaryGeneratedColumn({})
|
@PrimaryGeneratedColumn({})
|
||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
@ManyToOne(() => QuestionOption)
|
@ManyToOne(() => QuestionOption)
|
||||||
choice: QuestionOption;
|
@JoinColumn([
|
||||||
|
{ name: 'questionId', referencedColumnName: 'question' },
|
||||||
|
{ name: 'choiceId', referencedColumnName: 'choice' },
|
||||||
|
])
|
||||||
|
questionOption: QuestionOption;
|
||||||
|
|
||||||
@ManyToOne(() => Question, (question: Question) => question.answers)
|
@ManyToOne(() => Question, (question: Question) => question.answers)
|
||||||
|
@JoinColumn([{ name: 'questionId', referencedColumnName: 'id' }])
|
||||||
question: Question;
|
question: Question;
|
||||||
|
|
||||||
@ManyToOne(() => User)
|
@ManyToOne(() => User)
|
||||||
|
|||||||
Reference in New Issue
Block a user