Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
Loopback4 execute sql with params / ER_BAD_FIELD_ERROR: Unknown column 'reactionType' in 'field list'

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'

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think there are two issues in your code:

  1. ${} replacements do not work here
  2. parameter replacements are 1-to-1 with ? in order they appear

I couldn't test it but hope this should work

await this.newsReactionRepository.execute(
  'UPDATE `news_reaction` SET `?` = `?` + 1 WHERE `newsId` = ?', [reactionType,reactionType,id]
);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda