From 935a0490ae34e703a7b8b166b300b7f3c1d1862d Mon Sep 17 00:00:00 2001 From: Banach Technologies <80456992+banachtech@users.noreply.github.com> Date: Fri, 19 Apr 2024 01:57:52 +0800 Subject: [PATCH] Update store.rs 1. Change `question_id` to `corresponding_question` in `add_answer` method as the column `question_id` does not exist in `answers` table. 2. Add `RETURNING ...` to the SQL statement without which `fetch_one` will throw an error. --- ch_07/src/store.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ch_07/src/store.rs b/ch_07/src/store.rs index 9aeb140..62ca416 100644 --- a/ch_07/src/store.rs +++ b/ch_07/src/store.rs @@ -136,14 +136,14 @@ impl Store { new_answer: NewAnswer, ) -> Result { match sqlx::query( - "INSERT INTO answers (content, question_id) VALUES ($1, $2)", + "INSERT INTO answers (content, corresponding_question) VALUES ($1, $2) RETURNING id, content, corresponding_question", ) .bind(new_answer.content) .bind(new_answer.question_id.0) .map(|row: PgRow| Answer { id: AnswerId(row.get("id")), content: row.get("content"), - question_id: QuestionId(row.get("question_id")), + question_id: QuestionId(row.get("corresponding_question")), }) .fetch_one(&self.connection) .await