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

203
Views
Sequelize model with column using references ignores field option

I am not sure if this is a bug or issue with me, but I have this basic model

const { DataTypes } = require('sequelize');


  sequelize.define(
    'Submission',
    {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: DataTypes.INTEGER,
      },
      widgetId: {
        allowNull: false,
        type: DataTypes.INTEGER,
        references: {
          field: 'widget_id',
          model: {
            tableName: 'widget',
            schema: 'public',
          },
          key: 'id',
        },
        field: 'widget_id',
      },
      createdAt: {
        type: DataTypes.DATE,
        field: 'created_at',
      },
      updatedAt: {
        type: DataTypes.DATE,
        field: 'updated_at',
      },
    },
    {
      tableName: 'submission',
      timestamps: true,
      underscored: true,
    },
  );

and the widget model is identical except the columns/fields and has a id field. I am able to create a widget object / row in our db perfectly fine.

When trying to expand that and create a submission entry at same time as the widget, i expanded things and testing it out by adding the associations and test code as such

  widget.submission = widget.hasOne(submission);
  submission.widget = submission.belongsTo(widget);

  instance.models.Widget.create({
    widgetId: '123456789',
    title: 'test',
    Submission: {
      message: 'test',
    },
  }, {
    include: [{
      association: widget.submission,
    }]
  }).then(r => console.log(r))
    .catch(err => console.log(err));

and I get the following error

ValidationError [SequelizeValidationError]: notNull Violation: Submission.widgetId cannot be null

it seems to ignore my field: 'widget_id and assumes widgetId. The field option seems to work for everything else but this

anyway to handle that? thank you!

about 4 years ago · Juan Pablo Isaza
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!