Loopback4使用参数/ER_BAD_FIELD_ERROR执行sql:未知列'reactionType'在“字段列表”中
我想根据从 api 获取的“reactionType”值将表中“reactionType”列的值增加 1。反应类型是一个可变端点。例如/喜欢/不喜欢... 如果收到点赞,我会增加点赞栏的值。如果有不喜欢,我会增加不喜欢列的值。
@patch('/news-reaction/{id}/{reactionType}')
@response(204, {
description: 'updateReaction PATCH success',
})
async updateReaction(
@param.path.number('id') id: typeof News.prototype.id,
@param.path.string('reactionType') reactionType: string,
): Promise<void> {
await this.newsReactionRepository.execute('UPDATE `news_reaction` SET `${reactionType}` = `${reactionType}` +1 WHERE `newsId`=?', [id,reactionType]);
}
}
我收到错误。应该怎样呢?
错误:请求 PATCH /news-reaction/431224/sad 失败,状态代码为 500。错误:ER_BAD_FIELD_ERROR:“字段列表”中存在未知列“${reactionType}”
I want to increase the value of the 'reactionType' column in my table by 1 according to the 'reactionType' value I get from the api. reactionType is a variable endpoint. e.g /like /dislike ...
If a like is received, I will increase the value of the like column. If there is a dislike, I will increase the value of the dislike column..
@patch('/news-reaction/{id}/{reactionType}')
@response(204, {
description: 'updateReaction PATCH success',
})
async updateReaction(
@param.path.number('id') id: typeof News.prototype.id,
@param.path.string('reactionType') reactionType: string,
): Promise<void> {
await this.newsReactionRepository.execute('UPDATE `news_reaction` SET `${reactionType}` = `${reactionType}` +1 WHERE `newsId`=?', [id,reactionType]);
}
}
I'm getting an error. how should it be?
error: Request PATCH /news-reaction/431224/sad failed with status code 500. Error: ER_BAD_FIELD_ERROR: Unknown column '${reactionType}' in 'field list'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的代码中有两个问题:
我无法测试它,但希望这应该有效
I think there are two issues in your code:
I couldn't test it but hope this should work