Here is my first table question.
CREATE TABLE "question" (
"question_id" serial NOT NULL,
"question" TEXT NOT NULL UNIQUE,
"added_at" TIMESTAMP NOT NULL,
"question_marks" integer NOT NULL,
CONSTRAINT "question_pk" PRIMARY KEY ("question_id"))
Questions have many options, so I referring every option row with question_id
CREATE TABLE "option" (
"option_id" serial NOT NULL,
"option" TEXT NOT NULL,
"option_question_id" integer NOT NULL,
"option_correct" BOOLEAN NOT NULL,
CONSTRAINT "option_pk" PRIMARY KEY ("option_id"))
ALTER TABLE "option" ADD CONSTRAINT "option_fk1" FOREIGN KEY ("option_question_id") REFERENCES "question"("question_id") ON DELETE CASCADE;
Now, How can I update both tables in one query?
I building an API. The below-given output is for request. The request will response with question details and options for the question.
I am able to update question but questions have many options, How can I update options?
"questionDetails": [
{
"question_id": 30,
"question": "What is gravity of Saturn?",
"added_at": "2020-02-20T18:30:00.000Z",
"question_marks": 1
}
],
"options": [
{
"option_id": 19,
"option": "20",
"option_question_id": 30,
"option_correct": true
},
{
"option_id": 20,
"option": "30",
"option_question_id": 30,
"option_correct": false
},
{
"option_id": 21,
"option": "40",
"option_question_id": 30,
"option_correct": false
},
{
"option_id": 18,
"option": "400000000",
"option_question_id": 30,
"option_correct": false
}
]
}
Now Can I update this relation?