Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!