Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda