0

I want to remove multiple options if its question_id is 1 or 2.

The following code gives me this error: QueryFailedError: missing FROM-clause entry for table "option"

How do I solve this problem?

Service.ts:

this.QuizQuestionOptionRepository.createQueryBuilder('option')
  .delete()
  .from(QuizQuestionOption)
  .where('option.question_id IN (:...id)', { id: [1, 2] })
  .execute();

QuizQuestionOption entity:

import { QuizQuestion } from './quizQuestion.entity';
import {
  BeforeUpdate,
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';

@Entity()
export class QuizQuestionOption {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  title: string;

  @Column({ nullable: true })
  explanation: string;

  @Column()
  is_correct: boolean;

  @JoinColumn({ name: 'question_id' })
  @ManyToOne(() => QuizQuestion)
  question: QuizQuestion;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  created_at: Date;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  updated_at: Date;

  @BeforeUpdate()
  updateTimestamp() {
    this.updated_at = new Date();
  }
}

1 Answer 1

1

I dont think you need to add a name in createQueryBuilder. Maybe you should try it this way

await this.QuizQuestionOptionRepository.createQueryBuilder()
  .delete()
  .from(QuizQuestionOption)
  .where('question_id IN (:...id)', { id: [1, 2] })
  .execute();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. The problem was with the name & from. I removed both & it worked fine
nice @HasibulHasan

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.