当我使用findById(req.params.id)时,我的Sequelize查询始终会做出错误的查询

时间:2018-12-24 12:27:57

标签: javascript node.js postgresql sequelize.js

因此,我尝试进行更新查询,但是每次运行查询时,总是会得到错误的查找ID。 这是我第一次遇到这样的错误。 在我的其他项目中,这永远不会发生

QuestionController.updateQuestionAnswer = async (req, res, next) => {
    try {
        const questionAnswer = await QuestionAnswer.findById(req.params.id)
        console.log(questionAnswer)
        res.status(200).send({
            status_code: 200,
            questionAnswer,
            message: 'Updated'
        })
    } catch(error) {
        console.log(error)
        return res.status(500).send({ status_code: 500, message: error })
    }
}

Wrong Find By Id Where answer_id

1 个答案:

答案 0 :(得分:0)

您应该将其更改为WHERE子句,因为FindById仅在您有一个键(例如普通的Id)时才可以使用,而在有多个键(Answer_Id和Question_id)时不能使用或没有密钥。

const questionAnswer = await QuestionAnswer.where(x => x.question_id == req.params.id)