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

153
Vistas
Sequelize returns extra field and both, camel case and snake case foreign fields

When I make a request through Sequelize Model.findAll(), an event_id appears in the response that is not in the model, and also all Foreign keys come in both the snake and the camel case.

Sequelize call:

ChatMessage.findAll({ offset, limit, raw: true });

Result :

{
  campaignId: 1
  campaign_id: 1
  createdAt: "2022-01-11T21:41:39.931Z"
  event_id: null
  id: 3
  isCampaignMessage: true
  media: "https://link.com"
  message: "Text"
  messageFrom: "+11111111111"
  messageTo: "+11111111111"
  sid: "..."
  status: "..."
  targetId: 1
  target_id: 1
}

Query now:

SELECT "id",
       "target_id"           AS "targetId",
       "message_from"        AS "messageFrom",
       "message_to"          AS "messageTo",
       "message",
       "media",
       "sid",
       "status",
       "campaign_id"         AS "campaignId",
       "is_campaign_message" AS "isCampaignMessage",
       "created_at"          AS "createdAt",
       "campaign_id",
       "event_id",
       "target_id"
FROM "chat_message" AS "ChatMessage"
LIMIT 25 OFFSET 0;

But should be without the last 3 ids, cause they repeat.

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

0

Extra foreign fields can appear when you add not valid associate. The same was in my case, extra relation for event_id field.

Event.hasMany(models.Campaign, { foreignKey: 'event_id' });
Event.hasMany(models.ChatMessage, { foreignKey: 'event_id' }); // <--- Unnecessary association
Event.hasMany(models.Target, { foreignKey: 'event_i

As for the recurring cases, it was necessary to bring all associations foreign keys to the form of a camel case. Before that, they were in a snake case.

ChatMessage.belongsTo(models.Target, { foreignKey: '<target_id INTO targetId>' });
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